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

📄 shiyan7_1.java

📁 根据上课老师的要求
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class Shiyan7_1 extends Frame 
{Button b1=new Button("blue");
 Button b2=new Button("red");
 Label lab1=new Label("    ");
 public Shiyan7_1()
 {
  super("我的窗口");
  add(b1);
  add(b2);
  add(lab1);
  setLayout(new FlowLayout());
  setSize(200,200);
  setVisible(true);
  b1.addActionListener(new koActionListener());
  b2.addActionListener(new koActionListener());
  addWindowListener(new koWindowListener());
  }
 class koActionListener implements ActionListener
 {public void actionPerformed(ActionEvent e)
  {String ko=e.getActionCommand();
   if(ko.equals(b1.getLabel())){
 lab1.setText(b1.getLabel());
 lab1.setBackground(Color.blue);
   }
   else if(ko.equals(b2.getLabel())){
   lab1.setText(b2.getLabel());
   lab1.setBackground(Color.red);}
  }
 }
class koWindowListener extends WindowAdapter
{public void windowClosing(WindowEvent e)
 {e.getWindow().dispose();
  System.exit(0);
  }}
  public static void main(String args[])
  {new Shiyan7_1();}}

⌨️ 快捷键说明

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