作者ian810317 (西瓜瓜)
看板java
標題[問題] JAVA的繪圖程式 (大富翁)
時間Mon Jun 4 22:40:23 2012
為什麼我程式最後的PAINT()畫出的東西不會顯是在結果上面
以下這是程式碼
我沒有寫註解
對程式有問題或看不懂我在寫殺虫的話
我可以講一下我的程式構思(應該沒甚麼構思 感覺寫得很爛 QQ)
謝謝大家:D
//標籤 17-15
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TEST extends Frame
{
static TEST frm1=new TEST();
static Frame frm=new Frame("大富翁");
static Label lab00=new Label();
static Label lab01=new Label();
static Label labDice=new Label();
static Label lab11=new Label();
static Label lab21=new Label();
static Label lab31=new Label();
static Label lab41=new Label();
static Label lab51=new Label();
static Label lab61=new Label();
static Label lab71=new Label();
static Label lab81=new Label();
static Label lab91=new Label();
static Label lab101=new Label();
static Label lab12=new Label();
static Label lab13=new Label();
static Label lab14=new Label();
static Label lab15=new Label();
static Label lab16=new Label();
static Label lab17=new Label();
static Label lab18=new Label();
static Label lab19=new Label();
static Label lab110=new Label();
static Label lab210=new Label();
static Label lab310=new Label();
static Label lab410=new Label();
static Label lab510=new Label();
static Label lab610=new Label();
static Label lab710=new Label();
static Label lab810=new Label();
static Label lab910=new Label();
static Label lab1010=new Label();
static Label lab102=new Label();
static Label lab103=new Label();
static Label lab104=new Label();
static Label lab105=new Label();
static Label lab106=new Label();
static Label lab107=new Label();
static Label lab108=new Label();
static Label lab109=new Label();
static Button Dice=new Button("擲骰子");
public static void main(String args[])
{
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
Dice.addActionListener(new ActLis());
frm.setLayout(null);
frm.setSize(1366,646);
frm.setBackground(Color.white);
Dice.setBounds(420,263,120,80);
lab00.setText("大 富 翁");
lab00.setBackground(Color.white); //gray
lab00.setAlignment(Label.CENTER);
lab00.setForeground(Color.blue);
lab00.setLocation(100,96);
lab00.setSize(800,180);
lab01.setText("環遊世界");
lab01.setBackground(Color.white);
lab01.setAlignment(Label.CENTER);
lab01.setForeground(Color.blue);
lab01.setLocation(100,396);
lab01.setSize(800,180);
labDice.setText("你擲出 點");
labDice.setBackground(Color.white);
labDice.setAlignment(Label.CENTER);
labDice.setForeground(Color.blue);
labDice.setLocation(380,353);
labDice.setSize(200,40);
lab11.setText("往歐洲!!");
lab11.setBackground(Color.red);
lab11.setAlignment(Label.CENTER);
lab11.setForeground(Color.blue);
lab11.setLocation(0,36);
lab11.setSize(100,60);
lab21.setText("東京");
lab21.setBackground(Color.pink);
lab21.setAlignment(Label.CENTER);
lab21.setForeground(Color.blue);
lab21.setLocation(0,96);
lab21.setSize(100,60);
lab31.setText("北海道");
lab31.setBackground(Color.orange);
lab31.setAlignment(Label.CENTER);
lab31.setForeground(Color.blue);
lab31.setLocation(0,156);
lab31.setSize(100,60);
lab41.setText("大阪");
lab41.setBackground(Color.yellow);
lab41.setAlignment(Label.CENTER);
lab41.setForeground(Color.blue);
lab41.setLocation(0,216);
lab41.setSize(100,60);
lab51.setText("首爾");
lab51.setBackground(Color.green);
lab51.setAlignment(Label.CENTER);
lab51.setForeground(Color.blue);
lab51.setLocation(0,276);
lab51.setSize(100,60);
lab61.setText("北京");
lab61.setBackground(Color.pink);
lab61.setAlignment(Label.CENTER);
lab61.setForeground(Color.blue);
lab61.setLocation(0,336);
lab61.setSize(100,60);
lab71.setText("上海");
lab71.setBackground(Color.orange);
lab71.setAlignment(Label.CENTER);
lab71.setForeground(Color.blue);
lab71.setLocation(0,396);
lab71.setSize(100,60);
lab81.setText("四川");
lab81.setBackground(Color.yellow);
lab81.setAlignment(Label.CENTER);
lab81.setForeground(Color.blue);
lab81.setLocation(0,456);
lab81.setSize(100,60);
lab91.setText("廣東");
lab91.setBackground(Color.green);
lab91.setAlignment(Label.CENTER);
lab91.setForeground(Color.blue);
lab91.setLocation(0,516);
lab91.setSize(100,60);
lab101.setText("台北 起點");
lab101.setBackground(Color.red);
lab101.setAlignment(Label.CENTER);
lab101.setForeground(Color.blue);
lab101.setLocation(0,576);
lab101.setSize(100,60);
lab12.setText("倫敦");
lab12.setBackground(Color.pink);
lab12.setAlignment(Label.CENTER);
lab12.setForeground(Color.blue);
lab12.setLocation(100,36);
lab12.setSize(100,60);
lab13.setText("里斯本");
lab13.setBackground(Color.orange);
lab13.setAlignment(Label.CENTER);
lab13.setForeground(Color.blue);
lab13.setLocation(200,36);
lab13.setSize(100,60);
lab14.setText("巴黎");
lab14.setBackground(Color.yellow);
lab14.setAlignment(Label.CENTER);
lab14.setForeground(Color.blue);
lab14.setLocation(300,36);
lab14.setSize(100,60);
lab15.setText("漢堡");
lab15.setBackground(Color.green);
lab15.setAlignment(Label.CENTER);
lab15.setForeground(Color.blue);
lab15.setLocation(400,36);
lab15.setSize(100,60);
lab16.setText("阿姆斯特丹");
lab16.setBackground(Color.pink);
lab16.setAlignment(Label.CENTER);
lab16.setForeground(Color.blue);
lab16.setLocation(500,36);
lab16.setSize(100,60);
lab17.setText("巴塞隆納");
lab17.setBackground(Color.orange);
lab17.setAlignment(Label.CENTER);
lab17.setForeground(Color.blue);
lab17.setLocation(600,36);
lab17.setSize(100,60);
lab18.setText("馬德里");
lab18.setBackground(Color.yellow);
lab18.setAlignment(Label.CENTER);
lab18.setForeground(Color.blue);
lab18.setLocation(700,36);
lab18.setSize(100,60);
lab19.setText("羅馬");
lab19.setBackground(Color.green);
lab19.setAlignment(Label.CENTER);
lab19.setForeground(Color.blue);
lab19.setLocation(800,36);
lab19.setSize(100,60);
lab110.setText("往美西!!");
lab110.setBackground(Color.red);
lab110.setAlignment(Label.CENTER);
lab110.setForeground(Color.blue);
lab110.setLocation(900,36);
lab110.setSize(100,60);
lab210.setText("洛杉磯");
lab210.setBackground(Color.pink);
lab210.setAlignment(Label.CENTER);
lab210.setForeground(Color.blue);
lab210.setLocation(900,96);
lab210.setSize(100,60);
lab310.setText("鳳凰城");
lab310.setBackground(Color.orange);
lab310.setAlignment(Label.CENTER);
lab310.setForeground(Color.blue);
lab310.setLocation(900,156);
lab310.setSize(100,60);
lab410.setText("丹佛");
lab410.setBackground(Color.yellow);
lab410.setAlignment(Label.CENTER);
lab410.setForeground(Color.blue);
lab410.setLocation(900,216);
lab410.setSize(100,60);
lab510.setText("鹽湖城");
lab510.setBackground(Color.green);
lab510.setAlignment(Label.CENTER);
lab510.setForeground(Color.blue);
lab510.setLocation(900,276);
lab510.setSize(100,60);
lab610.setText("西雅圖");
lab610.setBackground(Color.pink);
lab610.setAlignment(Label.CENTER);
lab610.setForeground(Color.blue);
lab610.setLocation(900,336);
lab610.setSize(100,60);
lab710.setText("休士頓");
lab710.setBackground(Color.orange);
lab710.setAlignment(Label.CENTER);
lab710.setForeground(Color.blue);
lab710.setLocation(900,396);
lab710.setSize(100,60);
lab810.setText("達拉斯");
lab810.setBackground(Color.yellow);
lab810.setAlignment(Label.CENTER);
lab810.setForeground(Color.blue);
lab810.setLocation(900,456);
lab810.setSize(100,60);
lab910.setText("明尼蘇達");
lab910.setBackground(Color.green);
lab910.setAlignment(Label.CENTER);
lab910.setForeground(Color.blue);
lab910.setLocation(900,516);
lab910.setSize(100,60);
lab1010.setText("往美東!!");
lab1010.setBackground(Color.red);
lab1010.setAlignment(Label.CENTER);
lab1010.setForeground(Color.blue);
lab1010.setLocation(900,576);
lab1010.setSize(100,60);
lab102.setText("華盛頓");
lab102.setBackground(Color.pink);
lab102.setAlignment(Label.CENTER);
lab102.setForeground(Color.blue);
lab102.setLocation(100,576);
lab102.setSize(100,60);
lab103.setText("底特律");
lab103.setBackground(Color.orange);
lab103.setAlignment(Label.CENTER);
lab103.setForeground(Color.blue);
lab103.setLocation(200,576);
lab103.setSize(100,60);
lab104.setText("波士頓");
lab104.setBackground(Color.yellow);
lab104.setAlignment(Label.CENTER);
lab104.setForeground(Color.blue);
lab104.setLocation(300,576);
lab104.setSize(100,60);
lab105.setText("紐約");
lab105.setBackground(Color.green);
lab105.setAlignment(Label.CENTER);
lab105.setForeground(Color.blue);
lab105.setLocation(400,576);
lab105.setSize(100,60);
lab106.setText("邁阿密");
lab106.setBackground(Color.pink);
lab106.setAlignment(Label.CENTER);
lab106.setForeground(Color.blue);
lab106.setLocation(500,576);
lab106.setSize(100,60);
lab107.setText("費城");
lab107.setBackground(Color.orange);
lab107.setAlignment(Label.CENTER);
lab107.setForeground(Color.blue);
lab107.setLocation(600,576);
lab107.setSize(100,60);
lab108.setText("芝加哥");
lab108.setBackground(Color.yellow);
lab108.setAlignment(Label.CENTER);
lab108.setForeground(Color.blue);
lab108.setLocation(700,576);
lab108.setSize(100,60);
lab109.setText("紐澤西");
lab109.setBackground(Color.green);
lab109.setAlignment(Label.CENTER);
lab109.setForeground(Color.blue);
lab109.setLocation(800,576);
lab109.setSize(100,60);
Font fnt00=new Font("Serief",Font.BOLD,100);
Font fnt=new Font("Serief",Font.ITALIC+Font.BOLD,18);
Font fntDice=new Font("Serief",Font.BOLD,28);
lab00.setFont(fnt00);
lab01.setFont(fnt00);
labDice.setFont(fntDice);
lab11.setFont(fnt);
lab21.setFont(fnt);
lab31.setFont(fnt);
lab41.setFont(fnt);
lab51.setFont(fnt);
lab61.setFont(fnt);
lab71.setFont(fnt);
lab81.setFont(fnt);
lab91.setFont(fnt);
lab101.setFont(fnt);
lab12.setFont(fnt);
lab13.setFont(fnt);
lab14.setFont(fnt);
lab15.setFont(fnt);
lab16.setFont(fnt);
lab17.setFont(fnt);
lab18.setFont(fnt);
lab19.setFont(fnt);
lab110.setFont(fnt);
lab210.setFont(fnt);
lab310.setFont(fnt);
lab410.setFont(fnt);
lab510.setFont(fnt);
lab610.setFont(fnt);
lab710.setFont(fnt);
lab810.setFont(fnt);
lab910.setFont(fnt);
lab1010.setFont(fnt);
lab102.setFont(fnt);
lab103.setFont(fnt);
lab104.setFont(fnt);
lab105.setFont(fnt);
lab106.setFont(fnt);
lab107.setFont(fnt);
lab108.setFont(fnt);
lab109.setFont(fnt);
frm.add(lab00);
frm.add(lab01);
frm.add(labDice);
frm.add(lab11);
frm.add(lab21);
frm.add(lab31);
frm.add(lab41);
frm.add(lab51);
frm.add(lab61);
frm.add(lab71);
frm.add(lab81);
frm.add(lab91);
frm.add(lab101);
frm.add(lab12);
frm.add(lab13);
frm.add(lab14);
frm.add(lab15);
frm.add(lab16);
frm.add(lab17);
frm.add(lab18);
frm.add(lab19);
frm.add(lab110);
frm.add(lab210);
frm.add(lab310);
frm.add(lab410);
frm.add(lab510);
frm.add(lab610);
frm.add(lab710);
frm.add(lab810);
frm.add(lab910);
frm.add(lab1010);
frm.add(lab102);
frm.add(lab103);
frm.add(lab104);
frm.add(lab105);
frm.add(lab106);
frm.add(lab107);
frm.add(lab108);
frm.add(lab109);
frm.add(Dice);
frm.setVisible(true);
}
static class ActLis implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int rand;
rand=(int)(Math.random()*6+1);
labDice.setText("你擲出"+rand+"點");
}
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
Graphics g=getGraphics();
paint(g);
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillOval(1300,600,50,50);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 120.127.36.113
推 LaPass:一直剪下貼上不累嗎? = =" 你可以用list或是map去放Label 06/04 23:49
→ tkcn:這是世界奇觀呀! 06/04 23:57
→ ian810317:哈哈 那是甚麼?? 我剛學JAVA 只會土法煉鋼 06/05 00:03
推 pupuliao:我也是用類似的方法~~想學一下一樓說的方法~~~ 06/05 00:16
→ cooper6334:我覺得if-else金字塔比這101還更奇觀 06/05 02:08
推 LaPass:之前看過八皇后的迴圈世界奇觀..... XD 06/05 02:17
→ aceldama:用builder 寫code的話 label1.color(red).name(東京). 06/05 03:41
→ bera:我環遊到馬德里的時候就不爭氣的按下end了= = 06/05 03:56