java程序設計演算法研究課程設計
⑴ 《Java程序設計》課程設計畫隨機的圓
import java.awt.*;
import java.applet.*;
public class DrawRound extends Applet implements Runnable {
r;
int x,y;
public void init() {
x=(int)(Math.random()*getWidth());//隨機坐標
y=(int)(Math.random()*getHeight());
setSize(800,800);
r=10;//初始半徑=10
}
public void start() {
new Thread(this).start();//建立新線程
}
public void run() {
try {
while(true){
r+=10;
if(r==150){//當半徑=150時重新定義坐標,同時半徑等於初始狀態10
r=10;
x=(int)(Math.random()*getWidth()/2);
y=(int)(Math.random()*getHeight()/2);
}
Thread.sleep(500);//半徑每隔0.5秒就自動+10
repaint();//每次半徑變化時清空原來所畫的圓
}
}
catch(Exception e) {}
}
public void paint(Graphics g) {
g.setColor(new Color((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)));//隨機顏色
g.fillOval(x,y,r,r);//畫圓
}
}
⑵ 《JAVA程序設計》課程設計
1 package study.part02;
2 import java.util.Calendar;
3 import java.awt.*;
4 import javax.swing.*;
5 import java.awt.event.*;
6 import java.lang.Thread;
7 public class Clock extends JFrame implements ComponentListener,
8 ItemListener,Runnable{
9 Thread timer;
10 private JComboBox combobox_color;
11 public void start(){
12 if(timer==null)
13 timer=new Thread(this,"ShowTime");
14 timer.start();
15 }
16 public void run(){
17 while(true){
18 try{
19 timer.sleep(1000);
20 }catch(InterruptedException e){}
21 repaint();
22 }
23 }
24 public void stop(){
25 timer.stop();
26 }
27 public Clock(){
28 super("Clock");
29 this.setSize(600,600);
30 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
31 this.setLayout(new FlowLayout());
32
33 this.setVisible(true);
34 }
35 public void paint(Graphics g){
36 Calendar cal=Calendar.getInstance();
37 int year=cal.get(Calendar.YEAR);
38 int month=cal.get(Calendar.MONTH);
39 int day=cal.get(Calendar.DATE);
40 int hour=cal.get(Calendar.HOUR);
41 int minute=cal.get(Calendar.MINUTE);
42 int second=cal.get(Calendar.SECOND);
43 int a,b;
44 a=this.getWidth()/2;
45 for(int i=1;i<=360;i++){
46 double angle=i*Math.PI/180;
47 double radius=a-50;
48 int x=(int)Math.round(radius*Math.sin(angle));
49 int y=(int)Math.round(radius*Math.cos(angle));
50 if(i%30==0){
51 int j=i/30;
52 String str=String.valueOf(j);
53 g.setColor(Color.black);
54 // g.fillOval(a+x,a+y,1,1);
55 g.drawString(str,a+x,a-y);
56 }
57 double radh=a-200;
58 angle=hour*Math.PI/30;
59 int xh=(int)Math.round(radh*Math.sin(angle));
60 int yh=(int)Math.round(radh*Math.cos(angle));
61 g.setColor(Color.red);
62 g.drawLine(a,a,a+xh,a-yh);
63 double radm=a-150;
64 angle=minute*Math.PI/30;
65 int xm=(int)Math.round(radm*Math.sin(angle));
66 int ym=(int)Math.round(radm*Math.cos(angle));
67 g.setColor(Color.blue);
68 g.drawLine(a,a,a+xm,a-ym);
69 double rads=a-100;
70 angle=second*Math.PI/30;
71 int xs=(int)Math.round(rads*Math.sin(angle));
72 int ys=(int)Math.round(rads*Math.cos(angle));
73 g.setColor(Color.yellow);
74 g.drawLine(a,a,a+xs,a-ys);
75 //g.drawString(cal.get(Calendar.HOUR)+":"+cal.get(Calendar.
76 // MINUTE)+":"+cal.get(Calendar.SECOND));
77 }
78 }
79 public void itemStateChanged(ItemEvent e){
80 repaint();
81 }
82 public void componentResized(ComponentEvent e){
83 repaint();
84 }
85 public void componentMoved(ComponentEvent e){}
86 public void componentHidden(ComponentEvent e){}
87 public void componentShown(ComponentEvent e){}
88
89 public static void main(String[] args){
90 Clock show=new Clock();
91 show.start();
92 }
93 }
⑶ 《JAVA程序設計》結課設計
你應該問一些技術上的問題,而不是讓別人幫你做作業
⑷ 《Java程序設計》課程設計報告 表達式求值
import java.awt.*;
import java.applet.*;
public class DrawRound extends Applet implements Runnable {
int r;
int x,y;
public void init() {
x=(int)(Math.random()*getWidth());//隨機坐標
y=(int)(Math.random()*getHeight());
setSize(800,800);
r=10;//初始半徑=10
}
public void start() {
new Thread(this).start();//建立新線程
}
public void run() {
try {
while(true){
r =10;
if(r==150){//當半徑=150時重新定義坐標,同時半徑等於初始狀態10
r=10;
x=(int)(Math.random()*getWidth()/2);
y=(int)(Math.random()*getHeight()/2);
}
Thread.sleep(500);//半徑每隔0.5秒就自動 10
repaint();//每次半徑變化時清空原來所畫的圓
}
}
catch(Exception e) {}
}
public void paint(Graphics g) {
g.setColor(new Color((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)));//隨機顏色
g.fillOval(x,y,r,r);//畫圓
}
}
⑸ Java語言程序設計課程設計(求助,在線等)....
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import javax.swing.*;
public class CaiShu extends JFrame implements ActionListener{
private int number;
private JTextField jtf;
private JLabel label;
private JLabel label2;
private JButton jb1;
private JButton jb2;
private Date date1;
public CaiShu()
{
jtf = new JTextField(5);
label = new JLabel();
jb1 = new JButton("猜數");
jb1.addActionListener(this);
JPanel jp1 = new JPanel();
jp1.add(jtf);
jp1.add(jb1);
jp1.add(label);
setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
label2 = new JLabel();
JPanel jp2 = new JPanel();
jb2 = new JButton("重來");
jb2.addActionListener(this);
jp2.add(label2);
jp2.add(jb2);
add(jp2,BorderLayout.CENTER);
createNum();
this.setSize(400, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//隨機生成數字,並記下當前的的時間
public void createNum()
{
date1 = new Date();
this.number = (int)(Math.random()*100);
}
//返回評語
public String pingBi(int m)
{
if(m <=10) return "你是天才";
if(m <=15) return "你差點就成天才了";
return "你離天才還有段距離";
}
public void actionPerformed(ActionEvent e)
{
//按鍵"猜數"觸發的事件
if(e.getSource() == jb1)
{
try
{
int n = Integer.parseInt(jtf.getText());
if(n > number) label.setText("偏大");
if(n < number) label.setText("偏小");
if(n == number)
{
Date date2 = new Date();
int m = Math.round((date2.getTime() - date1.getTime())/1000);
label2.setText("恭喜你猜對了,共耗時"+m+"秒 "+ pingBi(m));
}
}catch(Exception ex)
{
JOptionPane.showConfirmDialog(null, "輸入有誤,請重新輸入","輸入錯誤",JOptionPane.PLAIN_MESSAGE);
jtf.setText("");
}
}
//按鍵"重來"觸發的事件
if(e.getSource() == jb2)
{
createNum();
jtf.setText("");
label.setText("");
label2.setText("");
}
}
public static void main(String[] args)
{
new CaiShu().setVisible(true);
}
}
⑹ java課程設計源代碼(急!!!!)
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class game21 extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();
public static void main(String[] args) {
new game21();
}
public game21() {
super("21點?!");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(170, 350, 106, 28);
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, 26));
label.setText("背面");
label.setBounds(158, 81, 137, 153);
getContentPane().add(label);
label_1.setText("你已經擁有的牌:");
label_1.setBounds(109, 22, 270, 45);
getContentPane().add(label_1);
this.setBounds(200, 300, 501, 528);
this.setVisible(true);
getContentPane().add(getLabel_2());
}
public int randNumber() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 10 + 1);
}
public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合計:" + sum;
label_2.setText(temp);
isWin();
}
public void isWin() {
if (sum > 21) {
JOptionPane.showMessageDialog(this, "你輸了");
clear();
return;
} else if (sum == 21) {
JOptionPane.showMessageDialog(this, "你贏了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否繼續?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}
private void clear() {
label_2.setText("合計:");
sum = 0;
number = 0;
label_1.setText("你已經擁有的牌:");
}
/**
* @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合計:");
label_2.setBounds(313, 35, 66, 18);
}
return label_2;
}
}
真好無聊中。。
⑺ JAVA課程設計
很簡單啊,看看書,學校給的教材看完就行了,這是一個動手的好機會,不要浪費了。