/** * Constructs a ClutoTree diaplay which is initialized with tableModel as the data model, and the * given selection model. * * @param clutoSolution The clustering solution * @param tableContext The context which manages views and selections. * @param tableModel the data model for the parallel coordinate display */ public ClutoTree(ClutoSolution clutoSolution, TableContext tableContext, TableModel tableModel) { ctx = tableContext; tm = tableModel; lsm = ctx.getRowSelectionModel(tm); // labelModel int ncol = tm.getColumnCount(); for (int i = 0; i < ncol; i++) { labelModel.addElement(tm.getColumnName(i)); } setLayout(new BorderLayout()); btnP = new JToolBar(); add(btnP, BorderLayout.NORTH); labelChoice.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { labelColumn = 0; String ln = (String) e.getItem(); if (ln != null) { for (int c = 0; c < tm.getColumnCount(); c++) { if (ln.equals(tm.getColumnName(c))) { labelColumn = c; break; } } } graph.invalidate(); validate(); repaint(); } } }); btnP.add(labelChoice); graph = new SimpleGraph(); graph.getGraphDisplay().setOpaque(true); graph.getGraphDisplay().setBackground(Color.white); graph.getGraphDisplay().setGridColor(new Color(220, 220, 220)); graph.showGrid(false); graph.showAxis(BorderLayout.WEST, false); graph.showAxis(BorderLayout.EAST, true); graph.getAxisDisplay(BorderLayout.EAST).setZoomable(true); graph.getAxisDisplay(BorderLayout.EAST).setAxisLabeler(labeler); ((LinearAxis) graph.getYAxis()).setTickIncrement(-1.); graph.getAxisDisplay(BorderLayout.SOUTH).setZoomable(true); gs = new GraphSegments(); gs.setColor(Color.blue); idxSelColor = new IndexSelectColor(Color.cyan, null, new DefaultListSelectionModel()); gs.setIndexedColor(idxSelColor); graph.addGraphItem(gs); graph.getGraphDisplay().addMouseListener(ma); add(graph); if (lsm != null) { lsm.addListSelectionListener(selListener); } display(makeTree(clutoSolution)); }
/** * Add a listener to the given combobox that will set the state to unconnected * * @param box The box to listen to. */ protected void clearOnChange(final JComboBox box) { box.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (!ignoreStateChangedEvents) { setState(STATE_UNCONNECTED); } } }); }
private void addPainter(myjava.gui.syntax.Painter painter) { EntryListPanel newPanel = new EntryListPanel(painter); listPanelSet.add(newPanel); centerPanel.add(newPanel, painter.getName()); painterComboBox.removeItemListener(painterChangeListener); painterComboBox.removeAllItems(); for (EntryListPanel p : listPanelSet) { painterComboBox.addItem(p.getPainter()); } removedPainters.remove(painter); painterComboBox.addItemListener(painterChangeListener); }
private void createComponents() { categoryLabel = new JLabel(Language.text("contrib.category")); categoryChooser = new JComboBox<String>(); categoryChooser.setMaximumRowCount(20); categoryChooser.setFont(Toolkit.getSansFont(14, Font.PLAIN)); updateCategoryChooser(); categoryChooser.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { category = (String) categoryChooser.getSelectedItem(); if (ContributionManagerDialog.ANY_CATEGORY.equals(category)) { category = null; } filterLibraries(category, filterField.filters); contributionListPanel.updateColors(); } }); filterField = new FilterField(); }
public DialogStammdaten(JFrame fenster, String[][] datensatz1, String s, Methoden datenbank1) { super(fenster, true); datenbank = datenbank1; datensatz = datensatz1; p = new JPanel(); platzhalter = new JLabel(); text1 = new JLabel("Name"); text2 = new JLabel("Personalnummer"); text3 = new JLabel("Titel"); text4 = new JLabel("Institut"); feld = new JComboBox(); textName = new JTextField(); textPersonalnr = new JTextField(); textInstitut = new JTextField(); textTitel = new JTextField(); menue = new JMenuBar(); datei = new JMenu("Datei"); aendern = new JMenuItem("Aendern"); hinzufuegen = new JMenuItem("Hinzufuegen"); loeschen = new JMenuItem("Loeschen"); beenden = new JMenuItem("Beenden"); final JDialog dialog = this; this.setTitle(s); feld = new JComboBox(ersteElemente(datensatz)); textName.setText(datensatz[0][0]); textPersonalnr.setText(datensatz[0][1]); setzen(datensatz, feld.getSelectedIndex()); feld.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getID() == ItemEvent.ITEM_STATE_CHANGED && e.getStateChange() == ItemEvent.SELECTED) { textName.setText((String) e.getItem()); textPersonalnr.setText(datensatz[feld.getSelectedIndex()][1]); setzen(datensatz, feld.getSelectedIndex()); } } }); datei.addMenuListener( new MenuListener() { public void menuSelected(MenuEvent e) { hinzufuegen.setEnabled(false); aendern.setEnabled(false); loeschen.setEnabled(false); if (!geaendert(datensatz, feld.getSelectedIndex())) { loeschen.setEnabled(true); } else if (!(textName.getText().equals("") || textPersonalnr.getText().equals(""))) { hinzufuegen.setEnabled(true); aendern.setEnabled(true); } } public void menuDeselected(MenuEvent e) {} public void menuCanceled(MenuEvent e) {} }); hinzufuegen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (hinzufuegen(daten)) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Hinzufuegen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); aendern.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (aendern(datensatz[feld.getSelectedIndex()][1], daten)) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Aendern geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); loeschen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (loeschen(datensatz[feld.getSelectedIndex()][1])) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Loeschen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); beenden.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); datei.add(hinzufuegen); datei.add(aendern); datei.add(loeschen); datei.add(beenden); menue.add(datei); this.setJMenuBar(menue); p.setLayout(new GridLayout(2, 5)); p.add(platzhalter); p.add(text1); p.add(text2); p.add(text3); p.add(text4); p.add(feld); p.add(textName); p.add(textPersonalnr); p.add(textTitel); p.add(textInstitut); this.setContentPane(p); this.pack(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
public Viewer() { leveldbStore.setMultiSelectionEnabled(false); leveldbStore.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); putButton.setEnabled(false); key.setEnabled(false); value.setEnabled(false); findField.setEnabled(false); deleteButton.setEnabled(false); saveButton.setEnabled(false); putType.setEnabled(false); putType.setEditable(false); signedBox.setEnabled(false); openButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (openButton.isEnabled()) { openButton.setEnabled(false); new Thread() { public void run() { if (leveldbStore.showOpenDialog(pane) == JFileChooser.APPROVE_OPTION) { File select = leveldbStore.getSelectedFile(); if (select.isDirectory()) { new OpenLevelDBDialog(Viewer.this, select); openDatabase(select); dbPathField.setText(select.getAbsolutePath()); } else { JOptionPane.showMessageDialog( pane, "The selecting item must be a directory", "Unable to load database", JOptionPane.WARNING_MESSAGE); } } else { openButton.setEnabled(true); } } }.start(); } } }); deleteButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dataList.getSelectedValue() != null) { delete(dataList.getSelectedValue().key); } openDatabase(leveldbStore.getSelectedFile()); } }); putButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { put( ((PutType) putType.getSelectedItem()).getBytes(key.getText()), ((PutType) putType.getSelectedItem()).getBytes(value.getText())); openDatabase(leveldbStore.getSelectedFile()); } }); findField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void removeUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void changedUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); hexKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexKey); } @Override public void removeUpdate(DocumentEvent e) { update(hexKey); } @Override public void changedUpdate(DocumentEvent e) { update(hexKey); } }); hexKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexKey); } }); stringKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringKey); } @Override public void removeUpdate(DocumentEvent e) { update(stringKey); } @Override public void changedUpdate(DocumentEvent e) { update(stringKey); } }); stringKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringKey); } }); hexValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexValue); } @Override public void removeUpdate(DocumentEvent e) { update(hexValue); } @Override public void changedUpdate(DocumentEvent e) { update(hexValue); } }); hexValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexValue); } }); stringValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringValue); } @Override public void removeUpdate(DocumentEvent e) { update(stringValue); } @Override public void changedUpdate(DocumentEvent e) { update(stringValue); } }); stringValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringValue); } }); saveButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); openDatabase(leveldbStore.getSelectedFile()); } }); dataList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dataList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { DBItem item = dataList.getSelectedValue(); if (item != null) { hexValue.setText(cutToLine(LevelDBViewer.toHexString(item.value), 64)); stringValue.setText(cutToLine(new String(item.value), 64)); hexKey.setText(cutToLine(LevelDBViewer.toHexString(item.key), 64)); stringKey.setText(cutToLine(new String(item.key), 64)); lengthLabel.setText(String.valueOf(item.value.length + item.key.length)); keyLength.setText(String.valueOf(item.key.length)); valueLength.setText(String.valueOf(item.value.length)); } } }); signedBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LevelDBViewer.DEFAULT_SINGED = signedBox.isSelected(); int i = dataList.getSelectedIndex(); dataList.clearSelection(); dataList.updateUI(); dataList.setSelectedIndex(i); update(hexKey); update(hexValue); } }); for (PutType t : PutType.values()) { putType.addItem(t); } putType.setSelectedItem(PutType.STRING); putType.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); putType.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); dialog.setLocationByPlatform(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setContentPane(pane); dialog.setTitle("LevelDB Viewer By Marcus (https://github.com/SuperMarcus)"); dialog.getRootPane().setDefaultButton(openButton); dialog.pack(); dialog.setVisible(true); }
public SyntaxTab() { super(new BorderLayout(), "Syntax highlighting"); /* * upper checkboxes */ JPanel upper = new JPanel(new GridLayout(2, 1, 0, 0)); upper.setOpaque(false); upper.add(MyPanel.wrap(highlightSyntax)); upper.add(MyPanel.wrap(matchBracket)); highlightSyntax.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { SyntaxTab.this.updateComponentStatus(); } }); this.add(upper, BorderLayout.PAGE_START); /* * upper panel (painters) */ painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getCurrentInstance()); painterComboBox.setFont(f13); if (isMetal) painterComboBox.setBackground(Color.WHITE); painterComboBox.addItemListener(this.painterChangeListener); JButton addPainter = new MyButton("+") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { String name; do { name = JOptionPane.showInputDialog( SyntaxTab.this, "Enter a name:", "Name", JOptionPane.QUESTION_MESSAGE); } while (!myjava.gui.syntax.Painter.isValidPrompt(name, SyntaxTab.this)); if ((name != null) && (!name.isEmpty())) { // name is valid, neither cancelled nor pressed enter directly myjava.gui.syntax.Painter newPainter = ((myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem())) .newInstance(name); addPainter(newPainter); System.out.println("now set, should call listener"); painterComboBox.setSelectedItem(newPainter); // auto-call ItemListener(s) } } }; JButton removePainter = new MyButton("-") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { myjava.gui.syntax.Painter painter = (myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem()); if (painter.equals(myjava.gui.syntax.Painter.getDefaultInstance())) { JOptionPane.showMessageDialog( SyntaxTab.this, "The default painter cannot be removed.", "Error", JOptionPane.ERROR_MESSAGE); } else { int option = JOptionPane.showConfirmDialog( SyntaxTab.this, "Remove painter \"" + painter.getName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { // remove "painter" removedPainters.add(painter); painterComboBox.removeItemListener(painterChangeListener); painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getDefaultInstance()); painterComboBox.removeItem(painter); for (Iterator<EntryListPanel> it = listPanelSet.iterator(); it.hasNext(); ) { EntryListPanel panel = it.next(); if (panel.getPainter().getName().equals(painter.getName())) { System.out.println("removing, then break"); it.remove(); centerPanel.remove(panel); break; } } painterComboBox.addItemListener(painterChangeListener); cardLayout.show( centerPanel, myjava.gui.syntax.Painter.getDefaultInstance().getName()); } } } }; // lower part JPanel center = new JPanel(new BorderLayout()); JLabel selectLabel = new MyLabel("Selected painter:"); center.add( MyPanel.wrap(MyPanel.CENTER, selectLabel, painterComboBox, addPainter, removePainter), BorderLayout.PAGE_START); componentSet.addAll(Arrays.asList(selectLabel, addPainter, removePainter)); center.add(centerPanel, BorderLayout.CENTER); this.add(center, BorderLayout.CENTER); cardLayout.show(centerPanel, myjava.gui.syntax.Painter.getCurrentInstance().getName()); }
/** * Create an AddeChooser associated with an IdvChooser * * @param mgr The chooser manager * @param root The chooser.xml node */ public AddeChooser(IdvChooserManager mgr, Element root) { super(mgr, root); simpleMode = !getProperty(IdvChooser.ATTR_SHOWDETAILS, true); this.addeServers = getIdv().getIdvChooserManager().getAddeServers(getGroupType()); serverSelector = new JComboBox(new Vector(addeServers)) { public void paint(Graphics g) { if (myServerTimeStamp != serverTimeStamp) { myServerTimeStamp = serverTimeStamp; Misc.runInABit(10, AddeChooser.this, "updateServerList", null); } super.paint(g); } }; serverSelector.setEditable(true); serverSelector.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (!ignoreStateChangedEvents) { setGroups(); } } }); serverSelector .getEditor() .getEditorComponent() .addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (!SwingUtilities.isRightMouseButton(e)) { return; } AddeServer server = getAddeServer(); if (server == null) { return; } List items = new ArrayList(); if (MARK_AS_INACTIVE || server.getIsLocal()) { items.add( GuiUtils.makeMenuItem( "Remove local server: " + server.getName(), AddeChooser.this, "removeServer", server)); } else { items.add(new JMenuItem("Not a local server")); } JPopupMenu popup = GuiUtils.makePopupMenu(items); popup.show(serverSelector, e.getX(), e.getY()); } }); groupSelector = new JComboBox(); groupSelector.setToolTipText("Right click to remove group"); groupSelector.setEditable(true); groupSelector .getEditor() .getEditorComponent() .addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Object selected = groupSelector.getSelectedItem(); if ((selected == null) || !(selected instanceof AddeServer.Group)) { return; } AddeServer.Group group = (AddeServer.Group) selected; List items = new ArrayList(); if (MARK_AS_INACTIVE || group.getIsLocal()) { items.add( GuiUtils.makeMenuItem( "Remove local group: " + group.getName(), AddeChooser.this, "removeGroup", group)); } final AddeServer server = getAddeServer(); if (server != null) { List groups = server.getGroupsWithType(getGroupType(), false); for (int i = 0; i < groups.size(); i++) { final AddeServer.Group inactiveGroup = (AddeServer.Group) groups.get(i); if (inactiveGroup.getActive()) { continue; } JMenuItem mi = new JMenuItem("Re-activate group: " + inactiveGroup); items.add(mi); mi.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { getIdv() .getIdvChooserManager() .activateAddeServerGroup(server, inactiveGroup); setGroups(); groupSelector.setSelectedItem(inactiveGroup); } }); } } if (items.size() == 0) { items.add(new JMenuItem("Not a local group")); } JPopupMenu popup = GuiUtils.makePopupMenu(items); popup.show(groupSelector, e.getX(), e.getY()); } } }); loadServerState(); setGroups(); }
public Assi() { c = getContentPane(); c.setLayout(new BorderLayout()); c.add(pnn, BorderLayout.NORTH); c.add(pns, BorderLayout.SOUTH); c.add(pnc, BorderLayout.CENTER); c.add(pne, BorderLayout.EAST); pne.setLayout(new GridLayout(2, 1)); pne.add(pne1); pne.add(pne2); pne1.setLayout(new FlowLayout()); pne1.add(go); go.addItem("Student"); go.addItem("Teacher"); go.addItem("Course"); go.addItem("Result"); pne1.add(b6); pne2.setLayout(cl2); pns.add(b1); pns.add(b2); pns.add(b3); pns.add(b4); pns.add(b5); setJMenuBar(m); m.add(student); m.add(teacher); m.add(course); m.add(result); stu.setLayout(new GridLayout(8, 2)); stu.add(l1); stu.add(t1); stu.add(l2); stu.add(t2); stu.add(l3); stu.add(t3); stu.add(l4); stu.add(t4); stu.add(l5); stu.add(t5); stu.add(l6); stu.add(t6); cou.setLayout(new GridLayout(4, 2)); cou.add(l7); cou.add(t7); cou.add(l8); cou.add(t8); cou.add(l9); cou.add(t9); cou.add(l0); cou.add(t0); tea.setLayout(new GridLayout(4, 2)); tea.add(l11); tea.add(t11); tea.add(l12); tea.add(t12); tea.add(l13); tea.add(t13); tea.add(l14); tea.add(t14); res.setLayout(new GridLayout(15, 3)); res.add(l15); res.add(t15); res.add(l16); res.add(t16); res.add(l17); res.add(t17); res.add(lg); res.add(l); res.add(l18); res.add(t18); res.add(l19); res.add(t19); res.add(l20); res.add(t20); res.add(l21); res.add(t21); res.add(l22); res.add(t22); res.add(l23); res.add(t23); res.add(l24); res.add(t24); res.add(l25); res.add(t25); res.add(l26); res.add(t26); res.add(l27); res.add(t27); res.add(l28); res.add(t28); pnc.setLayout(cl); pnc.add(blk, "cblk"); pnc.add(stu, "cstu"); pnc.add(tea, "ctea"); pnc.add(cou, "ccou"); pnc.add(res, "cres"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); student.addActionListener(this); teacher.addActionListener(this); course.addActionListener(this); result.addActionListener(this); go.addItemListener(this); }
editprof(String str, String user) { cp = getContentPane(); cp.setLayout(null); user1 = user; try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { } JTextField ft = new JTextField(); name1 = new JLabel("First Name"); try { r = new FileReader(user + "/First name.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } name = new JTextField(); name.setText(ft.getText()); last1 = new JLabel("Enter Last Name"); try { r = new FileReader(user + "/last name.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } last = new JTextField(); last.setText(ft.getText()); pass = new JLabel("Password"); try { r = new FileReader(user + "/password.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } pwd = new JPasswordField(); pwd.setText(ft.getText()); pwd.setEditable(false); email1 = new JLabel("Enter email address"); try { r = new FileReader(user + "/email.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } email = new JTextField(); email.setText(ft.getText()); addimage = new JButton("Add Image"); icon = new JLabel(); date1 = new JLabel("Date Of Birth"); date = new JComboBox(); for (int i = 1; i <= 31; i++) { date.addItem(i); } month = new JComboBox(); month.addItem("Jan"); month.addItem("Feb"); month.addItem("Mar"); month.addItem("Apr"); month.addItem("May"); month.addItem("Jun"); month.addItem("Jul"); month.addItem("Aug"); month.addItem("Sep"); month.addItem("Oct"); month.addItem("Nov"); month.addItem("Dec"); year = new JComboBox(); for (int j = 1900; j <= 2010; j++) { year.addItem(j); } sx = new JLabel("Gender"); gen = new JComboBox(); gen.addItem("Male"); gen.addItem("Female"); con1 = new JLabel("Country Name"); con = new JComboBox(); con.addItem(" Austrelia"); con.addItem(" America"); con.addItem(" Antartica"); con.addItem(" Africa"); con.addItem(" Canda"); con.addItem(" Corea"); con.addItem(" Chaina"); con.addItem(" Denmark"); con.addItem(" England"); con.addItem(" Franc"); con.addItem(" Hangery"); con.addItem(" Holand"); con.addItem(" Itali"); con.addItem(" India"); con.addItem(" Indonesia"); con.addItem(" Jermany"); con.addItem(" Japan"); con.addItem(" Korea"); con.addItem(" Kembridge"); con.addItem(" Merusalem"); con.addItem(" Noth America"); con.addItem(" Norvey"); con.addItem(" West Indies"); con.addItem(" Peru"); con.addItem(" Zimbawe"); about = new JLabel("About me"); try { r = new FileReader(user + "/about.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS; int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS; main = new JTextArea(); main.setText(ft.getText()); JScrollPane jsp = new JScrollPane(main, v, h); allow = new JLabel("Allow To:"); JCheckBox c1 = new JCheckBox(" orkut Friends"); JCheckBox c2 = new JCheckBox("Collage Friends"); JCheckBox c3 = new JCheckBox("Business Partner"); JCheckBox c4 = new JCheckBox("Relatives"); col = new JLabel("Collage Name:"); try { r = new FileReader(user + "/Collage.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } col1 = new JTextField(); col1.setText(ft.getText()); try { r = new FileReader(user + "/UniverSity.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } uni = new JLabel("Univercity"); uni1 = new JTextField(); uni1.setText(ft.getText()); state1 = new JLabel("State Name"); try { r = new FileReader(user + "/state.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } state = new JTextField(); state.setText(ft.getText()); city = new JLabel("City"); try { r = new FileReader(user + "/City.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } city1 = new JTextField(); city1.setText(ft.getText()); try { r = new FileReader(user + "/imagepath.txt"); ft.read(r, null); r.close(); } catch (Exception de) { } ImageIcon io = new ImageIcon(ft.getText()); icon.setIcon(io); next = new JButton("Update"); next.setBackground(Color.white); // adding to container name1.setBounds(10, 10, 130, 25); name.setBounds(150, 10, 130, 25); last1.setBounds(10, 40, 130, 25); last.setBounds(150, 40, 130, 25); email1.setBounds(10, 70, 130, 25); email.setBounds(150, 70, 130, 25); pass.setBounds(290, 70, 130, 25); pwd.setBounds(390, 70, 130, 25); addimage.setBounds(350, 440, 100, 25); icon.setBounds(490, 410, 100, 100); date1.setBounds(10, 100, 130, 25); date.setBounds(120, 100, 40, 25); month.setBounds(180, 100, 130, 25); year.setBounds(320, 100, 130, 25); sx.setBounds(10, 140, 130, 25); gen.setBounds(150, 140, 130, 25); about.setBounds(10, 180, 130, 25); jsp.setBounds(150, 180, 250, 80); allow.setBounds(10, 260, 130, 25); c1.setBounds(150, 260, 130, 25); c2.setBounds(290, 260, 130, 25); c3.setBounds(150, 290, 130, 25); c4.setBounds(290, 290, 130, 25); uni.setBounds(10, 330, 130, 25); uni1.setBounds(150, 330, 130, 25); col.setBounds(10, 360, 130, 25); col1.setBounds(150, 360, 130, 25); con1.setBounds(10, 390, 130, 25); con.setBounds(150, 390, 130, 25); state1.setBounds(10, 430, 130, 25); state.setBounds(150, 430, 130, 25); city.setBounds(10, 460, 130, 25); city1.setBounds(150, 460, 130, 25); next.setBounds(50, 490, 130, 25); cp.add(name); cp.add(name1); cp.add(last); cp.add(last1); cp.add(email); cp.add(email1); cp.add(addimage); cp.add(icon); cp.add(date1); cp.add(date); cp.add(month); cp.add(year); cp.add(about); cp.add(jsp); cp.add(sx); cp.add(gen); cp.add(allow); cp.add(c1); cp.add(c2); cp.add(c3); cp.add(c4); cp.add(next); cp.add(uni); cp.add(uni1); cp.add(col); cp.add(col1); cp.add(con); cp.add(con1); cp.add(state1); cp.add(state); cp.add(city); cp.add(city1); cp.add(next); cp.add(pwd); cp.add(pass); addimage.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { filepath = name.getText(); JFileChooser chooser = new JFileChooser(); while (true) { int val = chooser.showOpenDialog(editprof.this); File f = chooser.getSelectedFile(); String path = f.getPath(); String name = f.getName(); try { if (val == JFileChooser.CANCEL_OPTION || val == -1) { break; } else { image = new ImageIcon(path); icon.setIcon(image); w = new FileWriter(filepath + "/" + "imagePath.txt"); w.write(path + ""); w.close(); break; } } catch (Exception se) { } } } }); date.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { int str = (Integer) e.getItem(); File f = new File(name.getText()); f.mkdir(); try { w = new FileWriter(name.getText() + "/" + "date.txt"); w.write(str + ""); w.close(); } catch (IOException de) { } } }); month.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e1) { String str = (String) e1.getItem(); File f = new File(name.getText()); f.mkdir(); try { w = new FileWriter(name.getText() + "/" + "month.txt"); w.write(str + ""); w.close(); } catch (IOException de) { } } }); con.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e2) { String str = (String) e2.getItem(); File f = new File(name.getText()); f.mkdir(); try { w = new FileWriter(name.getText() + "/" + "contry.txt"); w.write(str + ""); w.close(); } catch (IOException de) { } } }); year.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e2) { int str = (Integer) e2.getItem(); File f = new File(name.getText()); f.mkdir(); try { w = new FileWriter(name.getText() + "/" + "year.txt"); w.write(str + ""); w.close(); } catch (IOException de) { } } }); gen.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e3) { String str = (String) e3.getItem(); File f = new File(name.getText()); f.mkdir(); try { w = new FileWriter(name.getText() + "/" + "gender.txt"); w.write(str + ""); w.close(); } catch (IOException de) { } } }); next.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent se) { try { w = new FileWriter(name.getText() + "/" + "First name.txt"); w.write(name.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "last name.txt"); w.write(last.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "email.txt"); w.write(email.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "Collage.txt"); w.write(col1.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "UniverSity.txt"); w.write(uni1.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "state.txt"); w.write(state.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "City.txt"); w.write(city1.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "about.txt"); w.write(main.getText()); w.close(); w = new FileWriter(name.getText() + "/" + "password.txt"); w.write(pwd.getText()); w.close(); profile e1 = new profile("My Profile", user1); e1.setVisible(true); e1.setLocation(00, 00); e1.setSize(800, 800); setVisible(false); } catch (Exception be) { } } }); }
InputFrame() { JPanel pane = new JPanel(); pane.setLayout(null); pane.setBackground(Color.LIGHT_GRAY); add(pane); // JTextField文字欄位元件 lblName = new JLabel("姓名:"); lblName.setBounds(10, 10, 40, 20); pane.add(lblName); text0.setBounds(50, 10, 80, 20); text0.addActionListener(textfield); pane.add(text0); // JSpinner數位序列元件 lblAge = new JLabel("年齡:"); lblAge.setBounds(170, 10, 40, 20); pane.add(lblAge); JSpinner spin = new JSpinner(new SpinnerNumberModel(20, 1, 100, 1)); spin.setBounds(210, 10, 80, 20); spin.addChangeListener(spinner); pane.add(spin); // JRadioButton選項圓鈕元件 lblSex = new JLabel("性別:"); lblSex.setBounds(10, 40, 40, 20); pane.add(lblSex); ButtonGroup group = new ButtonGroup(); JRadioButton rb1 = new JRadioButton("帥哥", false); rb1.setBounds(50, 40, 60, 20); JRadioButton rb2 = new JRadioButton("美女", false); rb2.setBounds(110, 40, 60, 20); rb1.setOpaque(false); rb2.setOpaque(false); // 秀出底色 rb1.addActionListener(radio); rb2.addActionListener(radio); group.add(rb1); group.add(rb2); pane.add(rb1); pane.add(rb2); // JCheckBox核對方塊元件 lblInter = new JLabel("興趣:"); lblInter.setBounds(10, 70, 50, 20); pane.add(lblInter); for (int i = 0; i < check.length; i++) { check[i] = new JCheckBox(checkItem[i]); check[i].setBounds(50 + 60 * i, 70, 60, 20); check[i].setOpaque(false); check[i].addActionListener(checkbox); pane.add(check[i]); } // JComboBox下拉式清單元件 lblAcad = new JLabel("學歷:"); lblAcad.setBounds(10, 100, 50, 20); pane.add(lblAcad); String[] items_c = {"博士", "碩士", "大學", "高中", "國中", "國小"}; JComboBox c_box = new JComboBox(items_c); c_box.setBounds(50, 100, 100, 20); c_box.addItemListener(cbo); pane.add(c_box); // JList清單元件 lblPlace = new JLabel("居住地區:"); lblPlace.setBounds(170, 100, 70, 20); pane.add(lblPlace); String[] items_p = { "台北", "桃園", "新竹", "苗栗", "台中", "彰化", "雲林", "嘉義", "台南", "高雄", "屏東", "花蓮", "台東", "澎湖" }; JList list = new JList(items_p); list.setVisibleRowCount(4); list.addListSelectionListener(list_p); JScrollPane scroll = new JScrollPane(list); scroll.setBounds(240, 100, 80, 80); pane.add(scroll); // JTextArea文字區域元件 texta.setBounds(10, 190, 330, 40); texta.setEditable(false); pane.add(texta); setTitle("輸入元件綜合應用"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(50, 50, 360, 280); setVisible(true); }