各位好,我知道我的程序是红色的部分但是怎么改呢??
package vo.cardClassTest;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;import java.awt.event.MouseAdapter;public class CardClassTest extends MouseAdapter {
//设置变量
//设置面板
Panel p1,p2,p3,p4,p5;
//设置标签
Label l1,l2,l3,l4,l5;
JFrame jf;
CardLayout cly;
public static void main(String[] args) {
CardClassTest clt = new CardClassTest();
clt.init();
}
public void init(){
jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cly = new CardLayout();
jf.setLayout(cly);
//创建面板
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
p5 = new Panel();
//创建标签
l1 = new Label("This is My First Label!!!!!");
l2 = new Label("This is My Second Label!!!!!");
l3 = new Label("This is My Third Label!!!!!");
l4 = new Label("This is My Four Label!!!!!");
l5 = new Label("This is My Five Label!!!!!");
//把标签添加到面板中
p1.add(l1);
p2.add(l2);
p3.add(l3);
p4.add(l4);
p5.add(l5);
//设置面板颜色
p1.setBackground(Color.orange);
p2.setBackground(Color.BLUE);
p3.setBackground(Color.yellow);
p4.setBackground(Color.green);
p5.setBackground(Color.RED);
//设置面板注册监听器
p1.addMouseListener(this);
p2.addMouseListener(this);
p3.addMouseListener(this);
p4.addMouseListener(this);
p5.addMouseListener(this);
//把面板添加到JFrame框架中
jf.add(p1,"First");
jf.add(p2,"Second");
jf.add(p3,"Three");
jf.add(p4,"Four");
jf.add(p5,"Five");
//卡片式布局管理器显示那个面板
cly.show(jf,"First");
jf.setSize(200,200);
jf.show();
}
public void mouseClicked(MouseEvent e){
cly.next(jf);
}
}
package vo.cardClassTest;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;import java.awt.event.MouseAdapter;public class CardClassTest extends MouseAdapter {
//设置变量
//设置面板
Panel p1,p2,p3,p4,p5;
//设置标签
Label l1,l2,l3,l4,l5;
JFrame jf;
CardLayout cly;
public static void main(String[] args) {
CardClassTest clt = new CardClassTest();
clt.init();
}
public void init(){
jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cly = new CardLayout();
jf.setLayout(cly);
//创建面板
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
p5 = new Panel();
//创建标签
l1 = new Label("This is My First Label!!!!!");
l2 = new Label("This is My Second Label!!!!!");
l3 = new Label("This is My Third Label!!!!!");
l4 = new Label("This is My Four Label!!!!!");
l5 = new Label("This is My Five Label!!!!!");
//把标签添加到面板中
p1.add(l1);
p2.add(l2);
p3.add(l3);
p4.add(l4);
p5.add(l5);
//设置面板颜色
p1.setBackground(Color.orange);
p2.setBackground(Color.BLUE);
p3.setBackground(Color.yellow);
p4.setBackground(Color.green);
p5.setBackground(Color.RED);
//设置面板注册监听器
p1.addMouseListener(this);
p2.addMouseListener(this);
p3.addMouseListener(this);
p4.addMouseListener(this);
p5.addMouseListener(this);
//把面板添加到JFrame框架中
jf.add(p1,"First");
jf.add(p2,"Second");
jf.add(p3,"Three");
jf.add(p4,"Four");
jf.add(p5,"Five");
//卡片式布局管理器显示那个面板
cly.show(jf,"First");
jf.setSize(200,200);
jf.show();
}
public void mouseClicked(MouseEvent e){
cly.next(jf);
}
}
import java.awt.event.*;
import javax.swing.*; import java.awt.event.MouseAdapter; public class CardClassTest extends MouseAdapter { //设置变量
//设置面板
Panel p1,p2,p3,p4,p5;
//设置标签
Label l1,l2,l3,l4,l5;
JFrame jf;
CardLayout cly; public static void main(String[] args) {
CardClassTest clt = new CardClassTest();
clt.init();
} public void init(){
jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cly = new CardLayout();
jf.setLayout(cly); //创建面板
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
p5 = new Panel(); //创建标签
l1 = new Label("This is My First Label!!!!!");
l2 = new Label("This is My Second Label!!!!!");
l3 = new Label("This is My Third Label!!!!!");
l4 = new Label("This is My Four Label!!!!!");
l5 = new Label("This is My Five Label!!!!!"); //把标签添加到面板中
p1.add(l1);
p2.add(l2);
p3.add(l3);
p4.add(l4);
p5.add(l5); //设置面板颜色
p1.setBackground(Color.orange);
p2.setBackground(Color.BLUE);
p3.setBackground(Color.yellow);
p4.setBackground(Color.green);
p5.setBackground(Color.RED); //设置面板注册监听器
p1.addMouseListener(this);
p2.addMouseListener(this);
p3.addMouseListener(this);
p4.addMouseListener(this);
p5.addMouseListener(this); //把面板添加到JFrame框架中
jf.add(p1,"First");
jf.add(p2,"Second");
jf.add(p3,"Three");
jf.add(p4,"Four");
jf.add(p5,"Five"); //卡片式布局管理器显示那个面板 cly.show(jf.getContentPane(), "First");
jf.setSize(200,200);
jf.show(); } public void mouseClicked(MouseEvent e){
cly.next(jf.getContentPane());
}
}
这样你试试吧。