Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - TF.e
Search - TF.e - List
写一个应用程序,要求编写一个Panel的子类MyPanel,MyPanel中有一个文本框和一个按钮,要求MyPanel的实例作为其按钮的ActionEvent事件的监视器,当单击按钮时,程序获取文本框中的文本,并将该文本作为按钮的名称。然后再编写一个Frame的子类,即窗口。窗口的布局为BorderLayout布局。窗口中添加两个MyPanel面板,分别添加到窗口的东部区域和西部区域-MyPanel.Java package cn import java.awt.* import java.awt.event.* public class MyPanel extends Panel implements ActionListener{ TextField tf Button bt public MyPanel() { tf=new TextField(10) bt=new Button("按钮") this.add(tf) this.add(bt) this.setLayout(new FlowLayout()) bt.addActionListener(this) this.setVisible(true) } public void actionPerformed(ActionEvent e) { if(e.getSource()==bt){ bt.setLabel(tf.getText()) } } } MyFrame.Java package cn import java.awt.BorderLayout import java.awt.Frame import java.awt.event.* public class MyFrame extends Frame { MyPanel p1,p2 public MyFrame() { p1=new MyPanel() p2=new MyPanel() this.setLayout(new BorderLayout()) this.add(p1) this.add(p2) this.setBounds(100,100,400,200) this.setVisible(true) this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent arg0) { System.exit(0) } }) this.
Date : 2025-12-20 Size : 4kb User :
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.