public ShowComp() throws InterruptedException, IOException { super("CONNECTED COMPUTERS"); int x = 0, d = 20; mb = new JMenuBar(); File = new JMenu("File"); mb.add(File); exit = new JMenuItem("Exit"); exit.addActionListener(this); File.add(exit); ta = new JTextArea(); ta.setBounds(20, 30, 315, 470); ta.setEditable(false); add(ta); setJMenuBar(mb); sel = new JLabel("The connected computers are.."); sel.setBounds(15, 5, 300, 30); add(sel); b1 = new JButton("<< BACK"); b1.setBounds(140, 510, 100, 30); b1.setToolTipText("Back to main page"); b1.addActionListener(this); add(b1); setLayout(null); while (x < 360) { x = x + d; setBounds(675, 50, x, 600); this.show(); } // setVisible(true); String s = "192.168.0.", temp = null; Printer printer = new Printer(); printer.start(); Connector connector = new Connector(printer); connector.start(); LinkedList targets = new LinkedList(); for (int i = 1; i <= 255; i++) { temp = s + Integer.toString(i); Target t = new Target(temp); targets.add(t); connector.add(t); } Thread.sleep(2000); connector.shutdown(); connector.join(); for (Iterator i = targets.iterator(); i.hasNext(); ) { Target t = (Target) i.next(); if (!t.shown) t.show(); } setDefaultCloseOperation(DISPOSE_ON_CLOSE); }
Port(Main frame, final int mode, String[] id) { super(NAME[mode] + "数据"); setSize(370, 200); setLocationRelativeTo(frame); setResizable(false); this.frame = frame; this.id = id; this.mode = mode; getContentPane().setLayout(null); JLabel csvLabel = new JLabel("CSV文件:"); csvLabel.setBounds(30, 35, 63, 16); getContentPane().add(csvLabel); JLabel picLabel = new JLabel("照片文件夹:"); picLabel.setBounds(30, 75, 78, 16); getContentPane().add(picLabel); csvField = new JTextField(); csvField.setBounds(120, 30, 134, 28); getContentPane().add(csvField); csvField.setColumns(10); csvLabel.setLabelFor(csvField); picField = new JTextField(); picField.setBounds(120, 70, 134, 28); getContentPane().add(picField); picField.setColumns(10); picLabel.setLabelFor(picField); final JButton csvButton = new JButton("选取..."); csvButton.setBounds(266, 30, 80, 29); getContentPane().add(csvButton); final JFileChooser csvChooser = new JFileChooser(); csvChooser.setFileFilter( new FileFilter() { @Override public boolean accept(File file) { boolean flag = false; if (file.isDirectory() || file.toString().endsWith(".csv")) flag = true; return flag; } @Override public String getDescription() { return "CSV 逗号分割的文件"; } }); csvButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int result; if (mode == 0) result = csvChooser.showOpenDialog(Port.this); else result = csvChooser.showSaveDialog(Port.this); if (result == JFileChooser.APPROVE_OPTION) csvField.setText(csvChooser.getSelectedFile().toString()); } }); final JButton picButton = new JButton("选取..."); picButton.setBounds(266, 70, 80, 29); getContentPane().add(picButton); final JFileChooser picChooser = new JFileChooser(); picChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); picButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int result; if (mode == 0) result = picChooser.showOpenDialog(Port.this); else result = picChooser.showSaveDialog(Port.this); if (result == JFileChooser.APPROVE_OPTION) picField.setText(picChooser.getSelectedFile().toString()); } }); progressBar = new JProgressBar(); progressBar.setBounds(30, 130, 160, 20); getContentPane().add(progressBar); final JButton button = new JButton("开始"); button.setBounds(230, 126, 117, 29); getContentPane().add(button); getRootPane().setDefaultButton(button); button.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { csvFile = new File(csvField.getText()); picDirectory = new File(picField.getText()); if (mode == 0) { if (!csvFile.exists() || csvFile.isDirectory() || !picDirectory.isDirectory()) { JOptionPane.showMessageDialog( Port.this, "请选择正确的文件", "注意", JOptionPane.INFORMATION_MESSAGE); return; } } else if (csvFile.exists() || (picDirectory.exists() && !picDirectory.isDirectory()) || csvFile.getPath().equals(picDirectory.getPath())) { JOptionPane.showMessageDialog( Port.this, "文件已存在", "注意", JOptionPane.INFORMATION_MESSAGE); return; } button.setEnabled(false); csvButton.setEnabled(false); picButton.setEnabled(false); csvField.setEnabled(false); picField.setEnabled(false); if (mode == 0) new Import().start(); else new Export().start(); } }); setVisible(true); }