java按一下按钮就能跳到另一个界面怎么实现
展开全部
java实现的简单登录页面,从一个按钮点击后跳转的页面的jframe写法:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jb{
public static void main(String args[]){
JFrame f=new JFrame("点我跳转");
Container contentPane=f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
Icon icon=new ImageIcon("b.jpg");
JLabel label2=new JLabel("a",icon,JLabel.CENTER);
label2.setHorizontalTextPosition(JLabel.CENTER);
contentPane.setLayout(new FlowLayout( FlowLayout.CENTER,10,10));
JButton bb=new JButton("图片");
bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame bf=new JFrame("新窗体");
Icon icon=new ImageIcon("enter.jpg");
JLabel label2=new JLabel(icon);
bf.getContentPane().add(label2);
bf.setSize(300,360);
bf.show();
}});
contentPane.add(label2);
contentPane.add(bb);
f.pack();
f.show();
}}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jb{
public static void main(String args[]){
JFrame f=new JFrame("点我跳转");
Container contentPane=f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
Icon icon=new ImageIcon("b.jpg");
JLabel label2=new JLabel("a",icon,JLabel.CENTER);
label2.setHorizontalTextPosition(JLabel.CENTER);
contentPane.setLayout(new FlowLayout( FlowLayout.CENTER,10,10));
JButton bb=new JButton("图片");
bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame bf=new JFrame("新窗体");
Icon icon=new ImageIcon("enter.jpg");
JLabel label2=new JLabel(icon);
bf.getContentPane().add(label2);
bf.setSize(300,360);
bf.show();
}});
contentPane.add(label2);
contentPane.add(bb);
f.pack();
f.show();
}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询