java点某个按钮,可以切换到下一个界面 跪求大神
今晚就要交作业了!!!跪求大神帮帮忙!第一个界面:importjava.awt.Color;importjava.awt.Font;importjava.awt.Grid...
今晚就要交作业了!!!跪求大神帮帮忙!第一个界面:import java.awt.Color;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.management.openmbean.OpenDataException;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class First extends JFrame implements ActionListener{ JPanel firstpane,pp,p1,p2,p3,p4; JButton jb1,jb2; JLabel L2; Font fontjb =new Font("幼圆", Font.CENTER_BASELINE,20); public First(){ /***************中部面板***************/ pp=(JPanel) getContentPane(); pp.setBackground(Color.CYAN); pp.setLayout(new GridLayout(3,8)); jb1=new JButton("进入-汽车租赁系统"); jb2=new JButton("退出-汽车租赁系统"); jb1.setFont(fontjb); jb2.setFont(fontjb); jb1.setBackground(Color.yellow); jb2.setBackground(Color.yellow); jb1.setForeground(Color.blue); jb2.setForeground(Color.blue); jb1.addActionListener(null); pp.add(new JLabel(new ImageIcon("IMAGE\\car1.jpg"))); pp.add(jb1); pp.add(jb2); /**************************************/ } public static void main(String[] args) { First f=new First(); f.setTitle("汽车租赁系统"); f.setSize(500,500); f.setDefaultCloseOperation(EXIT_ON_CLOSE); f.setVisible(true); } public void actionPerformed(ActionEvent e){ this.dispose(); second s=new second(); s.setVisible(true); }}是这样的两个Java文件 怎么点第一个出现第二个呢
第二个界面:
public class second extends JFrame{
JPanel p;
JButton d,x,n,b,z;
public second(){
p=(JPanel) getContentPane();
p.setLayout(new BorderLayout(6,6));
d=new JButton("中");
x=new JButton("西");
n=new JButton("南");
b=new JButton("北");
z=new JButton("中");
p.add(d,BorderLayout.EAST);
p.add(x,BorderLayout.WEST);
p.add(n,BorderLayout.SOUTH);
p.add(b,BorderLayout.NORTH);
p.add(z,BorderLayout.CENTER);
}
public static void main(String[] args) {
second t=new second();
t.setVisible(true);
}
} 展开
第二个界面:
public class second extends JFrame{
JPanel p;
JButton d,x,n,b,z;
public second(){
p=(JPanel) getContentPane();
p.setLayout(new BorderLayout(6,6));
d=new JButton("中");
x=new JButton("西");
n=new JButton("南");
b=new JButton("北");
z=new JButton("中");
p.add(d,BorderLayout.EAST);
p.add(x,BorderLayout.WEST);
p.add(n,BorderLayout.SOUTH);
p.add(b,BorderLayout.NORTH);
p.add(z,BorderLayout.CENTER);
}
public static void main(String[] args) {
second t=new second();
t.setVisible(true);
}
} 展开
1个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.management.openmbean.OpenDataException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class First extends JFrame implements ActionListener{
JPanel firstpane,pp,p1,p2,p3,p4;
JButton jb1,jb2;
JLabel L2;
Font fontjb =new Font("幼圆", Font.CENTER_BASELINE,20);
public First(){
pp=(JPanel) getContentPane();
pp.setBackground(Color.CYAN);
pp.setLayout(new GridLayout(3,8));
jb1=new JButton("进入-汽车租赁系统");
jb2=new JButton("退出-汽车租赁系统");
jb1.setFont(fontjb);
jb2.setFont(fontjb);
jb1.setBackground(Color.yellow);
jb2.setBackground(Color.yellow);
jb1.setForeground(Color.blue);
jb2.setForeground(Color.blue);
jb1.addActionListener(this); //************************************************
jb2.addActionListener(this); //************************************************
pp.add(new JLabel(new ImageIcon("IMAGE\\car1.jpg")));
pp.add(jb1); pp.add(jb2);
}
public static void main(String[] args) {
First f=new First();
f.setTitle("汽车租赁系统");
f.setSize(500,500);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){ //***********************************
if(e.getSource()==jb1){
this.dispose();
new second();
}
if(e.getSource()==jb2){
System.out.println("谢谢使用XX系统,再见!");
System.exit(0);
}
}
}
class second extends JFrame{
JPanel p;
JButton d,x,n,b,z;
public second(){
p=new JPanel();
p.setLayout(new BorderLayout(6,6));
d=new JButton("中");
x=new JButton("西");
n=new JButton("南");
b=new JButton("北");
z=new JButton("中");
p.add(d,BorderLayout.EAST);
p.add(x,BorderLayout.WEST);
p.add(n,BorderLayout.SOUTH);
p.add(b,BorderLayout.NORTH);
p.add(z,BorderLayout.CENTER);
//***************** 去掉主方法,改为下面几名***********************
setSize(300,300);
setLocationRelativeTo(null);
add(p);
setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询