extends JPanel 怎么用啊?
做的只是个插件,不能单独用这样理解对吗?
下面写好了,要如何加才能让它运行起来(最最简单的例子就可以)
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;public class CustomPane extends JPanel implements ActionListener
{
private JTextField tField;
public CustomPane()
{
setLayout(new FlowLayout());
initComponent();
}
private void initComponent()
{
tField = new JTextField(10);
add(tField);
JButton btn =new JButton();
add(btn);
btn.setText( "测试按钮");
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{}
}
做的只是个插件,不能单独用这样理解对吗?
下面写好了,要如何加才能让它运行起来(最最简单的例子就可以)
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;public class CustomPane extends JPanel implements ActionListener
{
private JTextField tField;
public CustomPane()
{
setLayout(new FlowLayout());
initComponent();
}
private void initComponent()
{
tField = new JTextField(10);
add(tField);
JButton btn =new JButton();
add(btn);
btn.setText( "测试按钮");
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{}
}
CustomPane cp=new CustomPane();
把cp add 到 frame;
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
JFrame f=new JFrame();
CustomPane cp=new CustomPane();
f.add(cp);
f.setSize(200,200);
f.setVisible(true); }}放到一个包下,可以看看!