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

📄 choiceapp.java~12~

📁 Java灵感设计范例源代码,和大家分享一下
💻 JAVA~12~
字号:
package choiceapp;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class choiceapp extends Applet {  boolean isStandalone = false;  Label label1 = new Label();  XYLayout xYLayout1 = new XYLayout();  Choice choice1 = new Choice();  Label label2 = new Label();  TextField textField1 = new TextField();  Label label3 = new Label();  TextField textField2 = new TextField();  Label label4 = new Label();  TextField textField3 = new TextField();  //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 choiceapp() {  }  //Initialize the applet  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception {    label1.setText("选择图形");    this.setLayout(xYLayout1);    label2.setText("长度");    textField1.setText("                     ");    label3.setText("宽度");    textField2.setText("  ");    label4.setText("弧度 ");    textField3.setText("  ");    choice1.addItemListener(new java.awt.event.ItemListener() {      public void itemStateChanged(ItemEvent e) {        choice1_itemStateChanged(e);      }    });    this.add(choice1,  new XYConstraints(113, 13, -1, 20));    this.add(label2,   new XYConstraints(70, 51, 44, 17));    this.add(textField1,   new XYConstraints(118, 53, 107, 25));    this.add(label3,    new XYConstraints(67, 90, 45, 28));    this.add(label4,     new XYConstraints(64, 123, 49, 23));    this.add(textField3,   new XYConstraints(120, 123, 109, 23));    this.add(label1,  new XYConstraints(51, 14, 59, 23));    this.add(textField2,  new XYConstraints(119, 95, 109, -1)); choice1.addItem("二维矩形");    choice1.addItem("椭圆形");    choice1.addItem("弧形");    choice1.addItem("三维矩形");  }  //Get Applet information  public String getAppletInfo() {    return "Applet Information";  }  //Get parameter info  public String[][] getParameterInfo() {    return null;  }  void choice1_itemStateChanged(ItemEvent e) { repaint();  }public void  paint(Graphics g){  String s1,s2,s3;//用于从文本框中获取字符串  int height,width,arc;//用于存放由字符串转换为整数  g.setColor(Color.blue );  s1=textField1.getText();  s2=textField2.getText();  s3=textField3.getText();  if(s1==null){//设置缺省值  s1="5";  textField1.setText(s1);}  if(s2==null){//设置缺省值  s2="5";  textField2.setText(s2);}  if(s3==null){//设置缺省值  s3="1";  textField3.setText(s3);} height=Integer.parseInt(s1); width=Integer.parseInt(s2); arc=Integer.parseInt(s3);  switch(choice1.getSelectedIndex()){  case 0: g.drawRect(80,150,height,width); break; case 1: g.drawOval(80,150,height,width); break; case  2: g.drawArc(80,150,height,width,0,arc); break; case 3: g.draw3DRect(80,150,height,width,true); break; default: g.drawString("error",80,150);  }  }  }

⌨️ 快捷键说明

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