Java界面编程实现界面跳转

作者:晚风难免些许微凉 时间:2023-11-12 00:56:45 

本文实例为大家分享了Java界面编程实现界面跳转的具体代码,供大家参考,具体内容如下

在事件处理中创建对象

public void actionPerformed(ActionEvent e)
            {
                QQ1 qq1=new QQ1();//为跳转的界面
 
            }

步骤:

在主函数中创建一个主窗口的对象

package 界面编程7;
 
public class QQmain {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        QQ qq = new QQ();
 
    }
 
}

 编写QQ类,该类中调用QQ1类、QQ2类  表达不正确,反正就是调用被调用类的构造方法

Java界面编程实现界面跳转

package 界面编程7;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
 
public class QQ extends JFrame implements ActionListener{
    public QQ() {
        this.setTitle("主界面");
        this.setBounds(100, 100, 300, 400);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
        
        
        FlowLayout layout = new FlowLayout();
        this.setLayout(layout);
        
        JButton jb1 = new JButton("弹出框");
        JButton jb2 = new JButton("跳转1");
        JButton jb3 = new JButton("跳转2");
        
        this.add(jb1);
        this.add(jb2);
        this.add(jb3);
        
        jb1.addActionListener(this);
        jb1.addActionListener(new ActionListener()        
        {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "提示内容" ,"标题", 2);
                
            }
        });
        
        
        
        jb2.addActionListener(this);
        jb2.addActionListener(new ActionListener()        
        {
            public void actionPerformed(ActionEvent e)
            {
                QQ1 qq1=new QQ1();//为跳转的界面
 
            }
        });
        
        
        jb3.addActionListener(this);
        jb3.addActionListener(new ActionListener()        
        {
            public void actionPerformed(ActionEvent e)
            {
                QQ2 qq2=new QQ2();//为跳转的界面
 
            }
        });
        
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        System.out.println("总处理");
    }
 
 
}

QQ1类  该类中调用QQ2类

Java界面编程实现界面跳转

package 界面编程7;
 
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
 
public class QQ1 extends JFrame implements ActionListener{
    public  QQ1() {
        this.setTitle("界面1");
        this.setBounds(200, 200, 300, 400);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
        
        
        FlowLayout layout = new FlowLayout();
        this.setLayout(layout);
        
        JButton jb1 = new JButton("跳转");
        
        
        this.add(jb1);
        jb1.addActionListener(this);
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        
        QQ2 qq3 = new QQ2();
        
    }
 
}

QQ2类

Java界面编程实现界面跳转

package 界面编程7;
 
import java.awt.FlowLayout;
 
import javax.swing.JFrame;
import javax.swing.JLabel;
 
public class QQ2 extends JFrame{
    public QQ2() {
        this.setTitle("界面2");
        this.setBounds(200, 200, 300, 400);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
        
        FlowLayout layout = new FlowLayout();
        this.setLayout(layout);
        
        JLabel jlb = new JLabel("界面2");
        this.add(jlb);
    }
 
}

Java界面编程实现界面跳转

来源:https://blog.csdn.net/qq_57867712/article/details/117136057

标签:java,界面跳转
0
投稿

猜你喜欢

  • ViewPager实现漂亮的引导页

    2022-12-27 21:56:58
  • Rxjava功能操作符的使用方法详解

    2021-06-10 06:57:16
  • Android中应用多进程的整理总结

    2022-05-05 04:25:21
  • C#中@的用法总结

    2023-03-11 10:02:51
  • Android7.0 MessageQueue详解

    2021-08-29 17:01:43
  • Java三目运算中隐藏的自动拆装箱

    2023-11-29 10:47:10
  • Java如何实现对称加密

    2021-07-01 09:29:11
  • Java实现邮箱找回密码实例代码

    2022-01-12 11:48:57
  • Android用Fragment创建选项卡

    2022-01-12 09:30:36
  • 20.5 语音合成(百度2016年2月29日发布的tts引擎)

    2022-06-26 06:55:01
  • Springboot实现高吞吐量异步处理详解(适用于高并发场景)

    2023-08-20 23:40:35
  • Android Studio升级到3.0后遇到的坑

    2022-01-23 00:59:07
  • Android自动播放Banner图片轮播效果

    2022-09-06 05:55:42
  • Java中的ArrayList容量及扩容方式

    2023-10-17 17:24:40
  • java实现二叉树遍历的三种方式

    2021-12-03 06:11:51
  • android 多点触摸图片缩放的具体实现方法

    2023-03-14 05:49:31
  • 详解C# Lazy Loading(延迟加载)

    2021-09-02 03:02:58
  • Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常

    2022-07-03 11:12:34
  • Windows下Flutter+Idea环境搭建及配置

    2022-01-22 18:12:13
  • SpringBoot实现监控Actuator,关闭redis监测

    2021-08-01 04:01:33
  • asp之家 软件编程 m.aspxhome.com