- 论坛徽章:
- 0
|
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
//安全卫士360界面基本实现
public class MainFrame extends JFrame implements ActionListener{
Box box = Box.createHorizontalBox();
JButton jb1 = new JButton("常用");
JButton jb2 = new JButton("杀毒");
JButton jb3 = new JButton("高级");
JButton jb4 = new JButton("保护");
JButton jb5 = new JButton("求助");
JButton jb6 = new JButton("推荐");
//页签组件
JTabbedPane jtp1 = new JTabbedPane();
JPanel jp1 = new JPanel(); //实际中应该定义一个继承JPanel类来实现
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
JPanel jp4 = new JPanel();
JPanel jp5 = new JPanel();
JTabbedPane jtp2 = new JTabbedPane();
JPanel jp6 = new JPanel();
JPanel jp7 = new JPanel();
//卡片布局
CardLayout card = new CardLayout();
JPanel jps = new JPanel();
public MainFrame()
{
//添加组件
box.add(jb1);
box.add(jb2);
box.add(jb3);
box.add(jb4);
box.add(jb5);
box.add(jb6);
//设置页签组件布局策略,一行显示
jtp1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
jtp1.add("基本状态",jp1);
jtp1.add("查杀流行木马",jp2);
jtp1.add("清理恶评插件",jp3);
jtp1.add("管理应用软件",jp4);
jtp1.add("修复系统漏洞",jp5);
jtp2.add("杀毒",jp6);
jtp2.add("在线杀毒",jp7);
jps.setLayout(card);
jps.add("changyong",jtp1);
jps.add("shadu",jtp2);
this.add(box,BorderLayout.NORTH);
this.add(jps,BorderLayout.CENTER);
jb1.addActionListener(this);
jb2.addActionListener(this);
//展现
this.setSize(500,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args)
{
new MainFrame();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1)
{
card.show(jps, "changyong");
}
else if(e.getSource()==jb2)
{
card.show(jps, "shadu");
}
}
}
效果图如下
![]()
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/62780/showart_490943.html |
|