Description: 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.
To Search:
File list (Check if you may need any files):
Demo8\.classpath
.....\.project
.....\.settings\org.eclipse.jdt.core.prefs
.....\bin\cn\test\MyFrame$1.class
.....\...\..\....\MyFrame.class
.....\...\..\....\MyPanel.class
.....\src\cn\test\MyFrame.java
.....\...\..\....\MyPanel.java
.....\bin\cn\test
.....\src\cn\test
.....\bin\cn
.....\src\cn
.....\.settings
.....\bin
.....\src
Demo8