import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class frame extends JFrame {
private JPanel pane=new JPanel();//放按钮的容器
private JPanel jp= new JPanel();//卡片的parent容器
private JPanel jpb=new JPanel();
private JButton b1=new JButton("图书查询");
private JButton b2=new JButton("外借图书");
private JButton b3=new JButton("返还图书");
private JButton b4=new JButton("系统管理");
private JButton b5=new JButton("退出系统");
private JPanel jp1=new JPanel();
private JPanel jp2=new JPanel();
private JPanel jp3=new JPanel();
private JPanel jp4=new JPanel();
private CardLayout card = new CardLayout(10,10 );
frame(){
pane.setLayout(null);
setLocation(100,80);
setTitle("图书管理系统");
jp.setLayout(card);
jp.setBounds(0,50,960,560);
jp1.setBounds(0,50,960,560);
jp2.setBounds(0,50,960,560);
jp3.setBounds(0,50,960,560);
jp4.setBounds(0,50,960,560);
b1.setBounds(230,10,90,30);
b2.setBounds(330,10,90,30);
b3.setBounds(430,10,90,30);
b4.setBounds(530,10,90,30);
b5.setBounds(630,10,90,30);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
jpb.setBounds(0,0,960,50);
jp1.setBackground(Color.WHITE);
jp2.setBackground(Color.DARK_GRAY);
jp3.setBackground(Color.darkGray);
jp4.setBackground(Color.BLUE);
jp.add(jp1,"p1");
jp.add(jp2,"p2");
jp.add(jp3,"p3");
jp.add(jp4,"p4");
b1.addActionListener(new ActionListener() { // 直接翻转到p_1
public void actionPerformed(ActionEvent e1) {
// System.out.println("p1");
card.show(jp, "p1");
}
});
b2.addActionListener(new ActionListener() { // 直接翻转到p_2
public void actionPerformed(ActionEvent e2) {
// System.out.println("p2");
card.show(jp, "p2");
}
});
b3.addActionListener(new ActionListener() { // 直接翻转到p_3
public void actionPerformed(ActionEvent e3) {
// System.out.println("p3");
card.show(jp, "p3");
}
});
b4.addActionListener(new ActionListener() { // 直接翻转到p_4
public void actionPerformed(ActionEvent e4) {
// System.out.println("p4");
card.show(jp, "p4");
}
});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e5){
System.exit(1);
} });
this.getContentPane().add(jp);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(960, 600);
this.setVisible(true);
this.setResizable(false);
}
}
public class test1 {
public static void main (String[] args) {
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
frame f=new frame();
f.show();
}
}我的几个按钮被覆盖,谁能帮我修改一下,谢谢!
import java.awt.event.*;
import javax.swing.*;
class frame extends JFrame {
private JPanel pane=new JPanel();//放按钮的容器
private JPanel jp= new JPanel();//卡片的parent容器
private JPanel jpb=new JPanel();
private JButton b1=new JButton("图书查询");
private JButton b2=new JButton("外借图书");
private JButton b3=new JButton("返还图书");
private JButton b4=new JButton("系统管理");
private JButton b5=new JButton("退出系统");
private JPanel jp1=new JPanel();
private JPanel jp2=new JPanel();
private JPanel jp3=new JPanel();
private JPanel jp4=new JPanel();
private CardLayout card = new CardLayout(10,10 );
frame(){
pane.setLayout(null);
setLocation(100,80);
setTitle("图书管理系统");
jp.setLayout(card);
jp.setBounds(0,50,960,560);
jp1.setBounds(0,50,960,560);
jp2.setBounds(0,50,960,560);
jp3.setBounds(0,50,960,560);
jp4.setBounds(0,50,960,560);
b1.setBounds(230,10,90,30);
b2.setBounds(330,10,90,30);
b3.setBounds(430,10,90,30);
b4.setBounds(530,10,90,30);
b5.setBounds(630,10,90,30);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
jpb.setBounds(0,0,960,50);
jp1.setBackground(Color.WHITE);
jp2.setBackground(Color.DARK_GRAY);
jp3.setBackground(Color.darkGray);
jp4.setBackground(Color.BLUE);
jp.add(jp1,"p1");
jp.add(jp2,"p2");
jp.add(jp3,"p3");
jp.add(jp4,"p4");
b1.addActionListener(new ActionListener() { // 直接翻转到p_1
public void actionPerformed(ActionEvent e1) {
// System.out.println("p1");
card.show(jp, "p1");
}
});
b2.addActionListener(new ActionListener() { // 直接翻转到p_2
public void actionPerformed(ActionEvent e2) {
// System.out.println("p2");
card.show(jp, "p2");
}
});
b3.addActionListener(new ActionListener() { // 直接翻转到p_3
public void actionPerformed(ActionEvent e3) {
// System.out.println("p3");
card.show(jp, "p3");
}
});
b4.addActionListener(new ActionListener() { // 直接翻转到p_4
public void actionPerformed(ActionEvent e4) {
// System.out.println("p4");
card.show(jp, "p4");
}
});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e5){
System.exit(1);
} });
this.getContentPane().add(jp);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(960, 600);
this.setVisible(true);
this.setResizable(false);
}
}
public class test1 {
public static void main (String[] args) {
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
frame f=new frame();
f.show();
}
}我的几个按钮被覆盖,谁能帮我修改一下,谢谢!
放到最后就解决了! 自己回了,来则有分,明天结帖