⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compare.java~10~

📁 很好得jbuilder100例源代码
💻 JAVA~10~
字号:
package untitled2;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;public class compare extends Applet {  int i = 1,j = 1;  double x = -1,y = -1;  boolean flag1 = false;  boolean flag2 = false;  boolean isStandalone = false;  XYLayout xYLayout1 = new XYLayout();  Button button1 = new Button();  Label label1 = new Label();  Label label2 = new Label();  Label label3 = new Label();  /**Get a parameter value*/  public String getParameter(String key, String def) {    return isStandalone ? System.getProperty(key, def) :      (getParameter(key) != null ? getParameter(key) : def);  }  /**Construct the applet*/  public compare() {  }  /**Initialize the applet*/  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  /**Component initialization*/  private void jbInit() throws Exception {    button1.setLabel("重玩");    button1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    this.setLayout(xYLayout1);    this.addMouseListener(new java.awt.event.MouseAdapter() {      public void mousePressed(MouseEvent e) {        this_mousePressed(e);      }    });    label2.setText("player1");    label3.setText("player2");    this.add(button1,  new XYConstraints(221, 207, 60, 23));    this.add(label1,  new XYConstraints(38, 233, 159, 24));    this.add(label2,  new XYConstraints(46, 21, 76, 24));    this.add(label3,  new XYConstraints(212, 19, 71, 28));  }  /**Get Applet information*/  public String getAppletInfo() {    return "Applet Information";  }  /**Get parameter info*/  public String[][] getParameterInfo() {    return null;  }  void this_mousePressed(MouseEvent e) {     if(!flag1){        flag1 = true;        label1.setText("轮到player1");     }     else{        if(!flag2){             x = 100 * Math.random();             label1.setText("轮到player2");             flag2 = !flag2;             repaint();        }        else{             y = 100 * Math.random();             label1.setText("轮到player1");             flag2 = !flag2;             repaint();        }      }   }   public void paint(Graphics g){       if(flag2){          if(x!=-1){              g.drawString(String.valueOf(x),30,60+15*i);              i += 1;          }       }       else{           if( y!= -1){              g.drawString(String.valueOf(y),150,60+15*j);              j += 1;           }       }       if((x>-1)&&(y>-1)){           if(x>y)              label1.setText("player1 win");           else              label1.setText("player2 win");       }    }  void button1_actionPerformed(ActionEvent e) {       x = -1;       y = -1;       flag1 = false;  }  public void update(Graphics g){     paint(g);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -