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

📄 example10_3.java

📁 很好
💻 JAVA
字号:
import java.awt.*;import java.applet.*;
import java.awt.event.*;
public class Example10_3 extends Applet 
{   public void init()
   {  MyButton1 button1=new MyButton1();
      MyButton2 button2=new MyButton2();
      setLayout(null);
      add(button1);add(button2);
      button1.setLocation(12,12);
      button2.setLocation(60,12);
   }
}
class MyButton1 extends Button implements ActionListener 
{  int n=-1;
   MyButton1()
   { setSize(25,160); addActionListener(this); 
   }
   public void paint(Graphics g) 
   {  g.drawString("我",6,14);  g.drawString("是",6,34);
      g.drawString("一",6,54);  g.drawString("个",6,74);
      g.drawString("竖",6,94);  g.drawString("按",6,114);
      g.drawString("钮",6,134); g.drawString("!",8,154);
   }
   public void actionPerformed(ActionEvent e)
   {  n=(n+1)%3;
      if(n==0)
         this.setBackground(Color.cyan);
      else if(n==1)
         this.setBackground(Color.orange);
      else if(n==2)
         this.setBackground(Color.pink);
   } 
}
class MyButton2 extends Button 
{  MyButton2()
   {  setSize(38,80); setBackground(Color.cyan);
   }
   public void paint(Graphics g)
   {  g.setColor(Color.red);
      g.fillOval(10,3,20,20);        //在按扭上画圆,见17章。
      g.setColor(Color.yellow);   g.fillOval(10,28,20,20);
      g.setColor(Color.green);    g.fillOval(10,53,20,20);
   }
}

⌨️ 快捷键说明

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