📄 swingts.java
字号:
jishibenDialog.setSize(600,500);
jishibenDialog.setLocation(500,500);
jishibenDialog.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
dispose();
}
});
}
}
class LeftPanel extends JPanel
{
private int i = 0;
public LeftPanel()
{
this.setBackground(Color.black);
this.setForeground(Color.red);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
DefaultMutableTreeNode select = new DefaultMutableTreeNode("select");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(""+i);
root.add(child);
root.add(select);
child.add(child1);
JTree tree = new JTree(root);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.setRowHeight(20);
tree.addTreeSelectionListener(new TreeSelectionListener ()
{
public void valueChanged(TreeSelectionEvent e)
{
JTree tree =(JTree)e.getSource();
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
i++;
selectNode.add(new DefaultMutableTreeNode(""+i));
}
});
tree.setPreferredSize(new Dimension(100,300));
JScrollPane scrollPane = new JScrollPane(tree);
this.add(scrollPane);
}
}
class BottomPanel extends JPanel
{
private JProgressBar pb;
public BottomPanel()
{
this.setBackground(Color.blue);
pb = new JProgressBar();
pb.setPreferredSize(new Dimension(680,20));
Timer time = new Timer(1,new ActionListener()
{
int counter = 0;
public void actionPerformed(ActionEvent e)
{
counter++;
pb.setValue(counter);
Timer t = (Timer)e.getSource();
if (counter == pb.getMaximum())
{
t.stop();
counter =0;
t.start();
}
}
});
time.start();
pb.setStringPainted(true);
pb.setMinimum(0);
pb.setMaximum(1000);
pb.setBackground(Color.red);
pb.setForeground(Color.black);
this.add(pb);
}
public void setProcessBar(BoundedRangeModel rangeModel)
{
pb.setModel(rangeModel);
}
}
class RightPanel extends JPanel
{
public RightPanel()
{
this.setLayout(new GridLayout(8,1));
this.setBackground(new Color(50,200,200));
JButton button = new JButton("打开文件");
button.setBackground(new Color(50,200,200));
JButton button1 = new JButton("钟表");
button1.setBackground(new Color(50,100,200));
JButton button2 = new JButton("计算器");
button2.setBackground(new Color(50,150,100));
JButton but4 = new JButton("动画");
but4.setBackground(new Color(180,150,200));
JButton but5 = new JButton("画板");
but5.setBackground(new Color(180,200,200));
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser file = new JFileChooser();
int result = file.showOpenDialog(new JPanel());
if (result ==file.APPROVE_OPTION)
{
String fileName = file.getSelectedFile().getName();
String dir = file.getCurrentDirectory().toString();
JOptionPane.showConfirmDialog(null,dir+"\\"+fileName,"选择的文件",JOptionPane.YES_OPTION);
}
}
});
button1.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e){
Clock clock=new Clock();
}
});
button2.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e){
jisuanqi qiyanjie=new jisuanqi();
}
});
but4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e){
temp kk=new temp();}
});
but5.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e){
MakeJPEG YY =new MakeJPEG();}
});
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton radioButton2 = new JRadioButton("单选按钮2",false);
JComboBox comboBox = new JComboBox();
comboBox.setToolTipText("点击下拉列表增加选项");
comboBox.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JComboBox comboBox =(JComboBox)e.getSource();
comboBox.addItem("程序员");
comboBox.addItem("分析员");
}
});
DefaultListModel litem = new DefaultListModel();
litem.addElement("香蕉");
litem.addElement("水果");
litem.addElement("英语");
litem.addElement("数学");
litem.addElement("语文");
litem.addElement("JAVA");
litem.addElement("政治");
litem.addElement("西藏");
JList list = new JList(litem);
list.addListSelectionListener(new ListSelectionListener ()
{
public void valueChanged(ListSelectionEvent e)
{
JList l = (JList)e.getSource();
Object s= l.getSelectedValue();
JOptionPane.showMessageDialog(null,s,"消息框",JOptionPane.YES_OPTION);
}
});
add(button);
add(button1);
add(but5);
add(but4);
add(button2);
add(comboBox);
add(list);
this.setBorder(new EtchedBorder(EtchedBorder.LOWERED,Color.LIGHT_GRAY,Color.blue));
}
}
class CenterPanel extends JPanel
{
public CenterPanel()
{
JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP);
tab.setBackground(new Color(100,50,100,200));
JTextField textField = new JTextField("文本域,点击打开<文件按钮>可选择文件");
textField.setActionCommand("textField");
JTextPane textPane = new JTextPane();
textPane.setCursor(new Cursor(Cursor.TEXT_CURSOR));
textPane.addMouseListener(new MouseAdapter ()
{
public void mousePressed (MouseEvent e)
{
JTextPane textPane = (JTextPane)e.getSource();
}
});
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,textField,textPane);
JTable table = new JTable(20,10);
JPanel pane = new JPanel();
pane.setForeground(Color.red);
JPanel pane2 = new JPanel();
pane2.setLayout(new BorderLayout());
pane.add(table.getTableHeader(),BorderLayout.NORTH);
pane.add(table);
JLabel hh1=new JLabel("设计人所在学校: 西藏大学");
hh1.setFont(new Font("楷体",Font.BOLD,25));
hh1.setForeground(new Color(120,118,200));
JLabel hh=new JLabel("设计人所在班级:04计算机教育班 ");
hh.setFont(new Font("楷体",Font.BOLD,25));
hh.setForeground(new Color(120,118,200));
JLabel hh2=new JLabel(" ");
JLabel hh3=new JLabel(" 欢迎使用 ");
hh3.setFont(new Font("楷体",Font.BOLD,47));
hh3.setForeground(new Color(60,118,200));
JLabel hh4=new JLabel(" ");
JLabel hh5=new JLabel(" 设计学生: 拉次 杨程智 ");
hh5.setFont(new Font("楷体",Font.BOLD,36));
hh5.setForeground(new Color(60,118,200));
tab.addTab("背景",pane2);
hh1.setBounds(50,50,450,100);
hh.setBounds(50,150,450,40);
pane2.add(hh1);
pane2.add(hh);
pane2.add(hh2);
pane2.add(hh3);
pane2.add(hh4);
pane2.add(hh5);
ImageIcon icon=new ImageIcon(".\\pc.jpg");
JLabel label=new JLabel(icon,JLabel.CENTER);
pane2.add(label,BorderLayout.CENTER);
pane2.setBackground(new Color(50,110,110,60));
pane2.setForeground(new Color(50,150,100,60));
tab.addTab("文本演示",splitPane);
tab.addTab("表格演示",pane);
pane.setBackground(Color.blue);
tab.setPreferredSize(new Dimension(500,600));
this.add(tab);
this.setEnabled(true);
}
}
public static void main(String args[])
{
new SwingTS();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -