java弹出新窗口
答案:1 悬赏:80
解决时间 2021-01-09 14:20
- 提问者网友:富士山上尢
- 2021-01-09 02:32
java弹出新窗口
最佳答案
- 二级知识专家网友:话散在刀尖上
- 2021-01-09 03:34
定义一个按钮的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(e);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(jButton1);
}
public static void main (String[] args)
{
Frame1 frame1=new Frame1();
}
public void jButton1_actionPerformed (ActionEvent e)
{
this.setVisible(false);
JFrame jf1=new JFrame("子窗口");
jf1.setBounds(100,50,800,600);
jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);
jf1.setVisible(true);
}
}
里面用写方法调用弹出窗口
代码
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(e);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(jButton1);
}
public static void main (String[] args)
{
Frame1 frame1=new Frame1();
}
public void jButton1_actionPerformed (ActionEvent e)
{
this.setVisible(false);
JFrame jf1=new JFrame("子窗口");
jf1.setBounds(100,50,800,600);
jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);
jf1.setVisible(true);
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯