package com.utstar.factory;
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.DefaultTableModel;
import com.utstar.factorymanager.*;
public class LittleWindow extends JFrame{ private static final long serialVersionUID = 6819222900970457455L; private JLabel label1,label2,label3,label4; private JTextField field1,field2,field3,field4; private JComboBox box; private JScrollPane scrollPane; private static JTextField field ; private static JButton sureButton; private static JButton cancelButton; public static TestTreeTable superModel = new TestTreeTable(); public LittleWindow(String name){ this.setBounds(300,300,500,400); this.setTitle(name); this.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.weightx = 1; gc.weighty = 10; gc.fill = GridBagConstraints.BOTH; gc.gridwidth = GridBagConstraints.REMAINDER; JPanel centerPanel = new JPanel(); centerPanel.setBorder(BorderFactory.createTitledBorder("增加内容")); field = new JTextField(); // field.setText("输入内容");
label1 = new JLabel("工厂名称"); label2 = new JLabel("工厂地址"); label3 = new JLabel("工厂类型"); label4 = new JLabel("工厂人数"); field1 = new JTextField(); field2 = new JTextField(); field3 = new JTextField(); field4 = new JTextField(); box = new JComboBox(); box.addItem("1"); box.addItem("2"); scrollPane = new JScrollPane(); // centerPanel.setLayout(new BorderLayout());
//
GridBagLayout centerLayout = new GridBagLayout(); centerPanel.setLayout(centerLayout); GridBagConstraints centerGc = new GridBagConstraints(); centerGc.fill = GridBagConstraints.BOTH; centerGc.weightx = 1; centerGc.weighty = 1; centerLayout.setConstraints(label1,centerGc); centerGc.weightx = 3; centerGc.gridwidth = GridBagConstraints.REMAINDER; centerLayout.setConstraints(field1,centerGc); centerGc.weighty = 2; centerGc.weightx = 1; centerGc.gridwidth = GridBagConstraints.BOTH; centerLayout.setConstraints(label2,centerGc); centerGc.weightx = 3; centerGc.gridwidth = GridBagConstraints.REMAINDER; scrollPane.getViewport().add(field2); scrollPane.setAutoscrolls(true); centerLayout.setConstraints(scrollPane,centerGc); centerGc.gridwidth = GridBagConstraints.BOTH; centerGc.weightx = 1; centerGc.weighty = 1; centerLayout.setConstraints(label3,centerGc); centerGc.gridwidth = GridBagConstraints.REMAINDER; centerGc.weightx = 3; centerLayout.setConstraints(box,centerGc); centerGc.gridwidth = GridBagConstraints.BOTH; // centerGc.gridheight = GridBagConstraints.REMAINDER;
centerGc.weightx = 1; centerGc.weighty = 1; centerLayout.setConstraints(label4,centerGc); centerGc.weightx = 3; centerGc.gridwidth = GridBagConstraints.REMAINDER; centerLayout.setConstraints(field4,centerGc); centerPanel.add(label1); centerPanel.add(field1); centerPanel.add(label2); centerPanel.add(scrollPane); centerPanel.add(label3); centerPanel.add(box); centerPanel.add(label4); centerPanel.add(field4); // centerPanel.add(field,BorderLayout.CENTER);
this.add(centerPanel,gc); gc.weighty = 1; JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new FlowLayout()); sureButton = new JButton("确定"); sureButton.setFont(new Font("宋体",3,20)); cancelButton = new JButton("取消"); cancelButton.setFont(new Font("宋体",3,20)); bottomPanel.add(sureButton,BorderLayout.CENTER); bottomPanel.add(cancelButton,BorderLayout.CENTER); addEvent(this); this.add(bottomPanel,gc); pack(); this.setVisible(true); } public static void addEvent(final LittleWindow w){ sureButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ DefaultTableModel model = (DefaultTableModel)w.superModel.table.getModel(); model.addRow(new Object[]{w.field1.getText(),w.field1.getText()}); w.superModel.table.validate(); w.dispose(); // w.superModel.table;
// w.superModel
// superModel.addData(field.getText(),field.getText());
// superModel.table.revalidate();
// w.dispose();
// w.setVisible(false);
} }); cancelButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ w.dispose(); } }); } public void setSuper(TestTreeTable model){ superModel = model; } public String getContent(){ return this.field.getText(); } public static void main(String args[]){ String name = "创建工厂"; LittleWindow win = new LittleWindow(name); } }
|