逛奔的蜗牛
我不聪明,但我会很努力
:: ::
新随笔
:: :: ::
管理
::
随笔分类
C/C++(67)
(rss)
Cocoa(26)
(rss)
Java(186)
(rss)
Mac(126)
(rss)
OpenGL(25)
(rss)
Qt(164)
(rss)
Qt自定义Widget(12)
(rss)
Xcode(5)
(rss)
其他编程(94)
(rss)
设计模式(2)
(rss)
外语(4)
(rss)
网文(74)
(rss)
搜索
最新评论
1. re: Java:用 Java 7 运行 IDEA 13
great post
--contact form
Java: 如TabbedPane一样显示多个面板: 设置时用得多
import
javax.swing.
*
;
import
java.awt.
*
;
import
java.awt.event.
*
;
public
class
MultiPanel
extends
JPanel
{
private
static
final
long
serialVersionUID
=
1L
;
private
JButton changeButton1;
private
JButton changeButton2;
private
JButton changeButton3;
private
JPanel panel1;
private
JPanel panel2;
private
JPanel panel3;
private
JPanel currentPanel;
public
MultiPanel()
{
this
.setLayout(
new
BorderLayout());
changeButton1
=
new
JButton(
"
<html><font color=red>Red Panel</font></html>
"
);
changeButton2
=
new
JButton(
"
<html><font color=green>Green Panel</font></html>
"
);
changeButton3
=
new
JButton(
"
<html><font color=blue>Blue Panel</font></html>
"
);
panel1
=
new
JPanel();
panel2
=
new
JPanel();
panel3
=
new
JPanel();
panel1.setBackground(Color.RED);
panel2.setBackground(Color.GREEN);
panel3.setBackground(Color.BLUE);
currentPanel
=
panel1;
Box box
=
Box.createHorizontalBox();
box.add(changeButton1);
box.add(changeButton2);
box.add(changeButton3);
this
.add(box, BorderLayout.SOUTH);
this
.add(currentPanel, BorderLayout.CENTER);
addButtonActionListener();
}
private
void
addButtonActionListener()
{
changeButton1.addActionListener(
new
ActionListener()
{
public
void
actionPerformed(ActionEvent e)
{
currentPanel.setVisible(
false
);
currentPanel
=
panel1;
currentPanel.setVisible(
true
);
add(currentPanel, BorderLayout.CENTER);
validate();
}
}
);
changeButton2.addActionListener(
new
ActionListener()
{
public
void
actionPerformed(ActionEvent e)
{
currentPanel.setVisible(
false
);
currentPanel
=
panel2;
currentPanel.setVisible(
true
);
add(currentPanel, BorderLayout.CENTER);
validate();
}
}
);
changeButton3.addActionListener(
new
ActionListener()
{
public
void
actionPerformed(ActionEvent e)
{
currentPanel.setVisible(
false
);
currentPanel
=
panel3;
currentPanel.setVisible(
true
);
add(currentPanel, BorderLayout.CENTER);
validate();
}
}
);
}
private
static
void
createAndShowGUI()
{
JFrame frame
=
new
JFrame(
"
Multi Panel
"
);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(
500
,
600
);
MultiPanel panel
=
new
MultiPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setVisible(
true
);
}
/** */
/**
*
@param
args
*/
public
static
void
main(String[] args)
{
SwingUtilities.invokeLater(
new
Runnable()
{
public
void
run()
{
MultiPanel.createAndShowGUI();
}
}
);
}
}
posted on 2008-03-22 18:35
逛奔的蜗牛
阅读(855)
评论(0)
编辑
收藏
引用
所属分类:
Java
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
相关文章:
Java:static final 变量的初始化
Java:Sublimetext格式化插件
Log4J 配置
Java:FastJson 主要API与类型
Java:用 Java 7 运行 IDEA 13
Java:Mavericks里安装Java 6
Qt:编码范围
Java:内存映射
Java:Java NIO之Buffer基础
Java:URLConnection访问网页
网站导航:
博客园
IT新闻
BlogJava
博问
Chat2DB
管理
Powered by:
C++博客
Copyright © 逛奔的蜗牛