JAVA入门 高级用户界面GUI设计.pptVIP

  • 2
  • 0
  • 约2.63万字
  • 约 105页
  • 2016-12-19 发布于贵州
  • 举报
* * * * * * * * * * * * * * * * * * * * * * * * * * 齐齐哈尔大学理学院 import java.awt.*; import java.applet.*; import java.awt.event.*; public class xy52 extends Applet implements ActionListener { Panel p1=new Panel(); PicPanel p2=new PicPanel(); Panel p3=new Panel(); private int price=1600; Label l1=new Label(); TextField tf1=new TextField(10); 第一个程序:xy52.java 齐齐哈尔大学理学院 public xy52() { setLayout(new BorderLayout()); p1.add(l1); p1.add(tf1); p2.initImg(); Button b1=new Button(开始游戏); b1.addActionListener(this); Button b2=new Button(确定); b2.addActionListener(this); Button b3=new Button(取消); b3.addActionListener(this); p3.add(b1); p3.add(b2); p3.add(b3); add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); add(p3,BorderLayout.SOUTH); setBackground(Color.white); } 齐齐哈尔大学理学院 public void actionPerformed(ActionEvent evt) { if(evt.getActionCommand().equals(开始游戏)) { p2.initImg(); l1.setText(输入商品价格:); p2.repaint(); setSize(500,200); } else if(evt.getActionCommand().equals(确定)) { int guessPrice=0; try { guessPrice=Integer.parseInt(tf1.getText().trim()); String guess=comparePrice(guessPrice); MsgDlg p4=new MsgDlg(guess); } //调用MsDlg类进行游戏结果显示,也可以用对话框. catch(Exception e) {e.printStackTrace();} } else if(evt.getActionCommand().equals(取消)) {tf1.setText();} } 齐齐哈尔大学理学院 public String comparePrice(int guessPrice) { if(guessPrice==price) { return 你猜对了,恭喜你!; } else if(guessPriceprice) {return 你猜的价格过高,请重新猜!“;} else if(guessPriceprice) { return 你猜的价格过低,请再加价!“; } return 出错了; } } 齐齐哈尔大学理学院 第二个程序:PicPanel.java import java.awt.*; import java.net.*; public class PicPanel extends Panel { public PicPanel() { initImg(); } String fileName = link.bmp.jpg; Image m_img; 齐齐哈尔大学理学院 public void initImg() { URL url = null; try { url = Class.forName(xy52).getResource(qu.jpg);} catch (Excep

文档评论(0)

1亿VIP精品文档

相关文档