java弹出新窗口

来源:百度知道 编辑:UC知道 时间:2024/05/28 17:59:17
我在做一个程序,需要在点击按钮时弹出一个带有标签和文本字段的新窗口,,请问怎样写代码?

定义一个按钮的OnClick事件
里面用写方法调用弹出窗口

代码
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Frame1 extends JFrame
{
private JButton jButton1=new JButton();

public Frame1 ()
{
try {
jbInit();
}
catch(Exception exception) {
exception.printStackTrace();
}
this.setVisible(true);
}

private void jbInit () throws Exception
{
this.setBounds(300,180,400,300);
getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(127, 120, 139, 36));
jButton1.setMnemonic('C');
jButton1.setText("点我(C)");
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
jButton1_actionPerformed(