swing 教程,与大家分享一下,哈哈,希望大家多多指教
源代码在线查看: clientpropertiestest.java
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
public class ClientPropertiesTest extends JApplet {
JButton button = new JButton("toggle target color");
JComboBox targetCombo = new JComboBox();
JPanel[] targets = { new JPanel(),
new JPanel(),
new JPanel() };
public void init() {
Container contentPane = getContentPane();
Dimension targetPreferredSize = new Dimension(100,100);
JPanel targetPanel = new JPanel();
for(int i=0; i < targets.length; ++i) {
targets[i].setBackground(Color.blue);
targets[i].setPreferredSize(targetPreferredSize);
targetPanel.add(targets[i]);
}
targetCombo.addItem("left");
targetCombo.addItem("center");
targetCombo.addItem("right");
contentPane.setLayout(new FlowLayout());
contentPane.add(button);
contentPane.add(targetCombo);
contentPane.add(targetPanel);
button.putClientProperty("target", targets[0]);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Component c =
(Component)button.getClientProperty("target");
if(c != null) {
Color bg = c.getBackground();
c.setBackground(bg == Color.blue ?
Color.red : Color.blue);
c.repaint();
}
}
});
targetCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.putClientProperty(
"target",
targets[targetCombo.getSelectedIndex()]);
}
});
button.addPropertyChangeListener(
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
if(e.getPropertyName().equals("target")) {
showStatus(
(String)targetCombo.getSelectedItem() +
" panel set as target");
}
}
});
}
public static void main(String args[]) {
final JFrame f = new JFrame();
JApplet applet = new ClientPropertiesTest();
applet.init();
f.setContentPane(applet.getContentPane());
f.setBounds(100,100,300,250);
f.setTitle("ClientPropertiesTest");
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.dispose();
System.exit(0);
}
});
}
}
|
相关资源 |
|
-
swing 教程,与大家分享一下,哈哈,希望大家多多指教
-
学习嵌入式 mmu 代码 感觉不错 发给大家分享一下了 希望大家喜欢 不错的
-
医院信息系统数据库设计, 大家分享一下
-
Java灵感设计范例源代码,和大家分享一下
-
这是我好辛苦才下载到的!!和大家分享一下
-
大二上学期期末的课程设计,自己做的比较详细,花了很多时间,与大家分享一下,希望大家也有好的程序借鉴.
-
我用vb编写modbus协议,拿出来与大家分享一下
-
一个音像租赁店铺的管理软件,可以维护影片库信息和会员信息,及日常业务的实现(出租/归还).这是我学delphi整一个月的纪念品,有些简单,不过我还是希望和大家分享一下我的成长历程.
|