当前位置:编程学习 > JAVA >>

JTabbedPane

在JTabbedPane两个标签切换的时候为什么会出现混乱啊


package memalloc;

import javax.swing.*;

public class Interface{
JFrame frame=new JFrame("a");
JPanel bestAllo=new BestAllocInterface();
JPanel firstAllo=new FirstAllocInterface();
public Interface()
{
JTabbedPane jtp=new JTabbedPane();
jtp.add("最佳适配算法",bestAllo);
jtp.add("最先适配算法",firstAllo);
frame.add(jtp);
frame.setSize(400, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new Interface();
}
}
package memalloc;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;

public class BestAllocInterface extends JPanel{
public void paintComponent(Graphics g)
{
g.setColor(Color.BLACK);
g.fillRect(50, 50, 100, 400);
JButton bt=new JButton("添加作业");
super.add(bt);
bt.setBounds(250, 400, 100, 50);
super.paintComponents(g);
}
}
package memalloc;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;

public class FirstAllocInterface extends JPanel{
public void paintComponent(Graphics g)
{
g.setColor(Color.BLACK);
g.fillRect(50, 50, 100, 400);
JButton bt=new JButton("添加作业");
super.add(bt);
bt.setBounds(250, 400, 100, 50);
super.paintComponents(g);
}
}
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,