Chinaunix首页 | 论坛 | 博客
  • 博客访问: 37034
  • 博文数量: 8
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-05 22:31
文章分类

全部博文(8)

文章存档

2008年(8)

我的朋友

分类: Java

2008-03-06 23:33:40

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");
        }
    }
    
}

 

效果图如下

阅读(1066) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~