文件名称:Demo8
介绍说明--下载内容均来自于网络,请自行研究使用
写一个应用程序,要求编写一个Panel的子类MyPanel,MyPanel中有一个文本框和一个按钮,要求MyPanel的实例作为其按钮的ActionEvent事件的监视器,当单击按钮时,程序获取文本框中的文本,并将该文本作为按钮的名称。然后再编写一个fr a me的子类,即窗口。窗口的布局为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())
}
}
}
Myfr a me.Java
package cn
import java.awt.BorderLayout
import java.awt.fr a me
import java.awt.event.*
public class Myfr a me extends fr a me {
MyPanel p1,p2
public Myfr a me()
{
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.
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())
}
}
}
Myfr a me.Java
package cn
import java.awt.BorderLayout
import java.awt.fr a me
import java.awt.event.*
public class Myfr a me extends fr a me {
MyPanel p1,p2
public Myfr a me()
{
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.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
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
.....\.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