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

📄 applet1.java

📁 是用java开发的一些程序原代码 是用java开发的一些程序原代码
💻 JAVA
字号:
package webpaint1;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;public class Applet1 extends Applet {  boolean isStandalone = false;  BorderLayout borderLayout1 = new BorderLayout();  Panel panel1 = new Panel();  Button button1 = new Button();  Button button2 = new Button();  Button button3 = new Button();  Button button4 = new Button();  Label label1 = new Label();  int startx,starty; //声明记录绘图起点的变量  int userchoose=1; //声明记录用户图形选择的变量  /**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 Applet1() {  }  /**Initialize the applet*/  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  /**Component initialization*/  private void jbInit() throws Exception {    this.setLayout(borderLayout1);    button1.setLabel("直线");    button1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button1_actionPerformed(e);      }    });    button2.setLabel("圆形");    button2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button2_actionPerformed(e);      }    });    button3.setLabel("矩形");    button3.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button3_actionPerformed(e);      }    });    button4.setLabel("圆角矩形");    button4.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        button4_actionPerformed(e);      }    });    label1.setText("现在位置");    this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {      public void mouseMoved(MouseEvent e) {        this_mouseMoved(e);      }    });    this.addMouseListener(new java.awt.event.MouseAdapter() {      public void mousePressed(MouseEvent e) {        this_mousePressed(e);      }      public void mouseReleased(MouseEvent e) {        this_mouseReleased(e);      }    });    this.add(panel1, BorderLayout.NORTH);    panel1.add(button1, null);    panel1.add(button2, null);    panel1.add(button3, null);    panel1.add(button4, null);    this.add(label1,  BorderLayout.SOUTH);  }  /**Get Applet information*/  public String getAppletInfo() {    return "Applet Information";  }  /**Get parameter info*/  public String[][] getParameterInfo() {    return null;  }  void this_mouseMoved(MouseEvent e) {  //在标签组件上显示目前鼠标的位置label1.setText("目前位置:"+e.getX()+","+e.getY());  }  void this_mousePressed(MouseEvent e) {startx=e.getX();//记录单击鼠标时的鼠标指针x轴坐标位置starty=e.getY();//记录单击鼠标时的鼠标指针y轴坐标位置  }//绘制圆形  void this_mouseReleased(MouseEvent e) { Graphics mypaint=getGraphics();switch (userchoose){  case 1://画直线        mypaint.drawLine(startx,starty,e.getX(),e.getY());  break;  case 2://画圆形        mypaint.drawOval(startx,starty,e.getX()-startx,e.getY()-starty);  break;  case 3://画矩形        mypaint.drawRect(startx,starty,e.getX()-startx,e.getY()-starty);  break;  case 4://画圆角矩形        mypaint.drawRoundRect(startx,starty,e.getX()-startx,e.getY()-starty,20,20);  break;}  }  //直线按钮  void button1_actionPerformed(ActionEvent e) {userchoose=1;  }//圆形按钮  void button2_actionPerformed(ActionEvent e) {userchoose=2;  }//矩形按钮  void button3_actionPerformed(ActionEvent e) {userchoose=3;  }//圆角矩形按钮  void button4_actionPerformed(ActionEvent e) {userchoose=4;  }}

⌨️ 快捷键说明

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