public class One extends JFrame{
private Two t;
public One() {
this.setTitle("图片管理器");
this.setSize(500, 400);
this.setLocationRelativeTo(null);
this.setResizable(false);
run();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private Two t;
public One() {
this.setTitle("图片管理器");
this.setSize(500, 400);
this.setLocationRelativeTo(null);
this.setResizable(false);
run();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private void run() {
t=new Two(this);
this.add(t);
}
public static void main(String[] args) {
new One();
}
t=new Two(this);
this.add(t);
}
public static void main(String[] args) {
new One();
}
public Two getT() {
return t;
}
return t;
}
public void setT(Two t) {
this.t = t;
}
this.t = t;
}
}
//两个JPanel
public class Two extends JPanel{
private There there;
private Four four;
public Two(final One o) {
this.setLayout(new CardLayout());
there=new There(o);
four=new Four(o);
this.add(there,"退出");
this.add(four, "返回");
}
private There there;
private Four four;
public Two(final One o) {
this.setLayout(new CardLayout());
there=new There(o);
four=new Four(o);
this.add(there,"退出");
this.add(four, "返回");
}
public There getThere() {
return there;
}
return there;
}
public void setThere(There there) {
this.there = there;
}
this.there = there;
}
public Four getFour() {
return four;
}
return four;
}
public void setFour(Four four) {
this.four = four;
}
}
this.four = four;
}
}
//第一个
public class There extends JPanel{
private Image image;
public There(final One o) {
this.setLayout(null);
Five five=new Five("一",70, 80, 110, 30,this);
Five five1=new Five("二",200, 80, 110, 30,this);
Five five2=new Five("三",330, 80, 110, 30,this);
Five five3=new Five("四",70, 150, 110, 30,this);
Five five4=new Five("五",200, 150, 110, 30,this);
Five five5=new Five("六",330, 150, 110, 30,this);
Five five6=new Five("退出",195, 240, 110, 30,this);
image= new ImageIcon("").getImage();
image= image.getScaledInstance(390, 210, 0);
five.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car=(CardLayout) o.getT().getLayout();
car.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/1.jpg"));
}
});
five1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car1=(CardLayout) o.getT().getLayout();
car1.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/15.jpg"));
}
});
five2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car2=(CardLayout) o.getT().getLayout();
car2.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/16.jpg"));
}
});
five3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car3=(CardLayout) o.getT().getLayout();
car3.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/4.jpg"));
}
});
five4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car4=(CardLayout) o.getT().getLayout();
car4.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/21.jpg"));
}
});
five5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car5=(CardLayout) o.getT().getLayout();
car5.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/23.jpg"));
}
});
five6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
public class There extends JPanel{
private Image image;
public There(final One o) {
this.setLayout(null);
Five five=new Five("一",70, 80, 110, 30,this);
Five five1=new Five("二",200, 80, 110, 30,this);
Five five2=new Five("三",330, 80, 110, 30,this);
Five five3=new Five("四",70, 150, 110, 30,this);
Five five4=new Five("五",200, 150, 110, 30,this);
Five five5=new Five("六",330, 150, 110, 30,this);
Five five6=new Five("退出",195, 240, 110, 30,this);
image= new ImageIcon("").getImage();
image= image.getScaledInstance(390, 210, 0);
five.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car=(CardLayout) o.getT().getLayout();
car.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/1.jpg"));
}
});
five1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car1=(CardLayout) o.getT().getLayout();
car1.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/15.jpg"));
}
});
five2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car2=(CardLayout) o.getT().getLayout();
car2.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/16.jpg"));
}
});
five3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car3=(CardLayout) o.getT().getLayout();
car3.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/4.jpg"));
}
});
five4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car4=(CardLayout) o.getT().getLayout();
car4.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/21.jpg"));
}
});
five5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car5=(CardLayout) o.getT().getLayout();
car5.show(o.getT(), "返回");
o.getT().getFour().getJlabel().setIcon(new ImageIcon("picture/23.jpg"));
}
});
five6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
}
//第二个
public class Four extends JPanel{
private JLabel jlabel;
public Four(final One o) {
this.setLayout(null);
jlabel= new JLabel();
jlabel.setBounds(100, 30, 280, 200);
this.add(jlabel);
Five five = new Five("返回主菜单", 180, 270, 120, 40, this);
this.add(five);
five.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car=(CardLayout) o.getT().getLayout();
car.show(o.getT(), "退出");
}
});
}
public JLabel getJlabel() {
return jlabel;
}
public void setJlabel(JLabel jlabel) {
this.jlabel = jlabel;
}
public class Four extends JPanel{
private JLabel jlabel;
public Four(final One o) {
this.setLayout(null);
jlabel= new JLabel();
jlabel.setBounds(100, 30, 280, 200);
this.add(jlabel);
Five five = new Five("返回主菜单", 180, 270, 120, 40, this);
this.add(five);
five.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CardLayout car=(CardLayout) o.getT().getLayout();
car.show(o.getT(), "退出");
}
});
}
public JLabel getJlabel() {
return jlabel;
}
public void setJlabel(JLabel jlabel) {
this.jlabel = jlabel;
}
}
import java.awt.Container;
import javax.swing.JButton;
/**
* @param name 按钮名称
* @param x 按钮横坐标
* @param y 按钮纵坐标
* @param width 按钮宽度
* @param height 按钮高度
* @param container 加入的容器
*/
public class Five extends JButton{
public Five(String name,int x,int y,int width,int height,Container container) {
super(name);
this.setBounds(x, y, width, height);
container.add(this);
}
/**
* @param name 按钮名称
* @param x 按钮横坐标
* @param y 按钮纵坐标
* @param width 按钮宽度
* @param height 按钮高度
* @param container 加入的容器
*/
public class Five extends JButton{
public Five(String name,int x,int y,int width,int height,Container container) {
super(name);
this.setBounds(x, y, width, height);
container.add(this);
}
}