java 窗口跳转
答案:6 悬赏:30 手机版
解决时间 2021-03-23 17:28
- 提问者网友:战魂
- 2021-03-22 23:36
java 窗口跳转
最佳答案
- 五星知识达人网友:从此江山别
- 2021-03-23 00:09
//////我已经把程序写的够简单了,一看就明白//
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends JFrame implements ActionListener {
private JPanel pan;
private JButton but;
MyFrame(){
this.setBounds(100, 100, 200, 200);
pan = new JPanel();
but = new JButton("点我出来新窗口");
but.addActionListener(this);
pan.add(but);
this.add(pan);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
public static void main(String args[]){
new MyFrame();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==but){
this.setVisible(false);
new Another();
}
}
class Another extends JFrame{
Another(){
this.setTitle("新窗口");
this.setBounds(300, 300, 200, 200);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
}
}
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends JFrame implements ActionListener {
private JPanel pan;
private JButton but;
MyFrame(){
this.setBounds(100, 100, 200, 200);
pan = new JPanel();
but = new JButton("点我出来新窗口");
but.addActionListener(this);
pan.add(but);
this.add(pan);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
public static void main(String args[]){
new MyFrame();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==but){
this.setVisible(false);
new Another();
}
}
class Another extends JFrame{
Another(){
this.setTitle("新窗口");
this.setBounds(300, 300, 200, 200);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
}
}
全部回答
- 1楼网友:不想翻身的咸鱼
- 2021-03-23 04:48
按钮跳转啊?那就直接是提交啊submi提交,提交路径action填写你提交路径就可以了
- 2楼网友:蓝房子
- 2021-03-23 03:52
完整程序没那个功夫,如果你说的是Swing开发的话,通常是在点击按钮的时候把当前窗口的对象传递给即将打开的子窗口,并在子窗口的onload事件中控制父窗口的显示状态。
- 3楼网友:枭雄戏美人
- 2021-03-23 02:36
原来窗口.dispose();
new 新窗口();
记忆当中,貌似是这样.
new 新窗口();
记忆当中,貌似是这样.
- 4楼网友:鸠书
- 2021-03-23 01:17
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test1 extends JFrame{
JButton bt1,bt2;
public Test1(){
bt1 = new JButton("first");
bt2 = new JButton("exit");
bt2.setVisible(false);
bt1.addActionListener(new MyListener());
bt2.addActionListener(new MyListener());
this.getContentPane().setLayout(new GridLayout(6,6));
this.getContentPane().add(bt1);
this.getContentPane().add(bt2);
this.setSize(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public class MyListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
if(arg0.getActionCommand().equals("first")){
bt1.setVisible(false);
bt2.setVisible(true);
}else
System.exit(0);
}
}
public static void main(String[] args) {
Test1 test = new Test1();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test1 extends JFrame{
JButton bt1,bt2;
public Test1(){
bt1 = new JButton("first");
bt2 = new JButton("exit");
bt2.setVisible(false);
bt1.addActionListener(new MyListener());
bt2.addActionListener(new MyListener());
this.getContentPane().setLayout(new GridLayout(6,6));
this.getContentPane().add(bt1);
this.getContentPane().add(bt2);
this.setSize(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public class MyListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
if(arg0.getActionCommand().equals("first")){
bt1.setVisible(false);
bt2.setVisible(true);
}else
System.exit(0);
}
}
public static void main(String[] args) {
Test1 test = new Test1();
}
}
- 5楼网友:逐風
- 2021-03-23 00:25
你没有必要在关闭一个窗口后新建一个窗口,你可以采用布局管理器里边的CardLayout布局管理器,具体实施你查查资料 很简单的 就设置为可见与不可见 this.setVisable(true);…………如果不明白 可以再给我发信息
我Q: 372630075
我Q: 372630075
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯