// --------------------------------actionHost--------------------------------- private void actionHost() { if (oParty == null) { JOptionPane.showMessageDialog(frame, "Make a party before trying to connect."); return; } JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY); int nReturn = oFC.showOpenDialog(frame); if (nReturn == JFileChooser.CANCEL_OPTION) { return; } int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame))); JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame)); dlgBox.pack(); try { oConn.host(nPort); } catch (IOException e) { JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } dlgBox.setVisible(false); echo("Connected to opponent!"); tConn = new Thread(oConn, "conn"); tConn.start(); tMain = new Thread(this, "main"); tMain.start(); try { oMap.loadMap(oFC.getSelectedFile()); oConn.send("loadmap", oFC.getName(oFC.getSelectedFile())); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
@Override public void actionPerformed(ActionEvent arg0) { try { URL url = new URL(excelUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); int filesize = connection.getContentLength(); float totalDataRead = 0; java.io.BufferedInputStream in = new java.io.BufferedInputStream(connection.getInputStream()); java.io.FileOutputStream fos = new java.io.FileOutputStream(excelName); java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 14921); byte[] data = new byte[14921]; int i = 0; JOptionPane jop2 = new JOptionPane("VitalHealth Test Automation Framework"); JDialog k2 = jop2.createDialog("Please wait till file is downloaded"); k2.setModal(false); k2.setVisible(true); while ((i = in.read(data, 0, 14921)) >= 0) { totalDataRead = totalDataRead + i; bout.write(data, 0, i); float Percent = (totalDataRead * 100) / filesize; } bout.close(); in.close(); // fos.close(); k2.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Sample Configuration file downloaded"); } }
public char[] askPassword() { char[] password = null; final JDialog dlg = new JDialog(frm, "Password", true); final JPasswordField jpf = new JPasswordField(15); final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")}; for (int i = 0; i < btns.length; i++) { btns[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dlg.setVisible(false); } }); } Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long"); System.exit(1); } return password; }
/** * Common event handling code - can handle desirable actions (such as buttons being clicked) and * undesirable actions (the window being closed) all in a common location. * * @param command a String representing the action that occurred. */ private void processCommand(String command) { dialog.setVisible(false); if (CONNECT.equals(command)) { options.setValue(JOptionPane.OK_OPTION); } else { options.setValue(JOptionPane.CANCEL_OPTION); } }
/** * shows a color chooser dialog * * @param initialColor the initial Color set when the color-chooser is shown * @return the selected color or <code>null</code> if the user opted out */ public Color showColorChooserDialog(Color initialColor) { setColor(initialColor); SVGColorTracker ok = new SVGColorTracker(this); JDialog dialog = createDialog(Editor.getParent(), "", true, this, ok, null); dialog.setVisible(true); return ok.getColor(); }
public void edit(Evaluator evaluator, JFrame parent) { if (!(evaluator instanceof Evaluator)) { return; // error? } // create an editor dialog box JDialog editor = new Editor(parent, (Evaluator) evaluator); editor.setVisible(true); }
public void actionPerformed(ActionEvent e) { System.out.println("[*** EditSpeakersAction ***]"); ApplicationControl ac = (ApplicationControl) applicationControl; JDialog dialog = new JDialog(ac.getFrame(), true); EditSpeakerPanel editSpeakerPanel = new EditSpeakerPanel(ac.getTranscription()); dialog.setTitle(FOLKERInternationalizer.getString("dialog.speaker.editspeakers")); dialog.getContentPane().add(editSpeakerPanel); dialog.pack(); dialog.setLocationRelativeTo(ac.getFrame()); dialog.setVisible(true); ac.speakersChanged(); }
public static void startDownload(JFrame frame, List<CardInfo> allCards) { ArrayList<CardDownloadData> cards = getNeededCards(allCards); /* * if (cards == null || cards.size() == 0) { * JOptionPane.showMessageDialog(null, * "All card pictures have been downloaded."); return; } */ DownloadPictures download = new DownloadPictures(cards); JDialog dlg = download.getDlg(frame); dlg.setVisible(true); dlg.dispose(); download.setCancel(true); }
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("New Game")) { newGame(); } if (e.getActionCommand().equals("Exit Game")) { exit(); } if (e.getActionCommand().equals("About")) { JDialog f = new JDialog(); f.add(new JLabel(new ImageIcon("splash_applet.jpg"))); f.setSize(660, 520); f.setLocationRelativeTo(this); f.setVisible(true); } }
public void login() { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:orcl"; Connection con = null; Statement stmt = null; ResultSet rs = null; String id, pw, sql; try { Class.forName(driver); con = DriverManager.getConnection(url, "hr", "hr"); stmt = con.createStatement(); sql = "select * from chatuser where id = '" + lid.getText() + "'"; rs = stmt.executeQuery(sql); if (rs.next()) { pw = rs.getString(2); nick = rs.getString(3); if (lpw.getText().equals(pw)) { jd.setVisible(false); setVisible(true); } else { lpw.setText("일치하지 않습니다."); } } else { lid.setText("일치하지 않습니다."); } } catch (Exception e1) { e1.printStackTrace(); System.out.println("데이터 베이스 연결 실패!!"); } finally { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); } catch (Exception e1) { System.out.println(e1.getMessage()); } } }
public void run() { // Collect some user data. dlg = new JDialog(console.frame, "Example 1 Setup", true); dlg.getContentPane().setLayout(new BorderLayout()); // Properties area propPanel = new JPanel(); dlg.getContentPane().add(propPanel, BorderLayout.CENTER); GridBagLayout gbl = new GridBagLayout(); propPanel.setLayout(gbl); // List of voice resources DefaultListModel dlm = new DefaultListModel(); for (int x = 1; ; x++) { try { int c = x % 4 == 0 ? 4 : x % 4; int b = c == 4 ? x / 4 : x / 4 + 1; String devName = "dxxxB" + b + "C" + c; int dev = dx.open(devName, 0); try { // If any of the voice resources _are not_ connected to // analog loop-start lines, then they will be suppressed // here because sethook() will not be supported. dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC); dlm.addElement(devName); } catch (Exception ignore) { } dx.close(dev); } catch (Exception ignore) { break; } } analogDxList = new JList(dlm); { GridBagConstraints gbc; // Choose a voice resource: gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; JTextField t = new JTextField("Analog Voice Resource"); t.setEditable(false); gbl.setConstraints(t, gbc); propPanel.add(t); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; JScrollPane s = new JScrollPane(analogDxList); gbl.setConstraints(s, gbc); propPanel.add(s); } // Dialog buttons at the bottom. JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH); // "Run" { JButton b = new JButton("Run"); b.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { final Object[] dx = analogDxList.getSelectedValues(); if (dx.length != 1) { // "Please select one, and only one, voice resource." JOptionPane.showMessageDialog( dlg, "Please select one, and only one, resource.", "Error", JOptionPane.ERROR_MESSAGE); return; } Thread t = new Thread() { public void run() { runExample((String) dx[0]); } }; t.start(); dlg.dispose(); } }); buttonPanel.add(b); } // "Cancel" { JButton b = new JButton("Cancel"); b.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { dlg.dispose(); } }); buttonPanel.add(b); } // Pack and Show dlg.pack(); dlg.setLocationRelativeTo(console.frame); dlg.setVisible(true); }
public EchoAWT() throws UnknownHostException { super("채팅 프로그램"); // 각종 정의 h = new JPanel(new GridLayout(2, 3)); m = new JPanel(new BorderLayout()); f = new JPanel(new BorderLayout()); s = new JPanel(new BorderLayout()); login = new JPanel(new BorderLayout()); // name = new JLabel(" 사용자 이름 "); name = new JLabel(" 메세지 입력 "); jta = new JTextArea(); // clientList = new JTextArea(0, 10); clientList = new JList(); jsp = new JScrollPane(jta); list = new JScrollPane(clientList); jtf = new JTextField("입력하세요."); hi = new JTextField("HOST IP 입력"); pi = new JTextField("PORT 입력"); localport = new JTextField("원하는 PORT 입력"); lid = new JTextField("ID를 입력하세요."); lpw = new JTextField("PW를 입력하세요."); serveropen = new JButton("서버 오픈"); textin = new JButton("입력"); clientin = new JButton("서버 접속"); conf = new JButton("로그인"); join = new JButton("회원가입"); addr = InetAddress.getLocalHost(); // 사용자 해상도 및 창 크기 설정 및 가져오기. Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); setSize(500, 500); Dimension d = getSize(); // 각종 버튼 및 텍스트 필드 리스너 jtf.addActionListener(this); hi.addActionListener(this); pi.addActionListener(this); localport.addActionListener(this); lid.addActionListener(this); lpw.addActionListener(this); conf.addActionListener(this); join.addActionListener(this); serveropen.addActionListener(this); clientin.addActionListener(this); textin.addActionListener(this); jtf.addFocusListener(this); hi.addFocusListener(this); pi.addFocusListener(this); localport.addFocusListener(this); lid.addFocusListener(this); lpw.addFocusListener(this); // 서버 접속 h.add(hi); h.add(pi); h.add(clientin); // 서버 생성 h.add(new JLabel("IP : " + addr.getHostAddress(), (int) CENTER_ALIGNMENT)); h.add(localport); h.add(serveropen); // 채팅글창 글 작성 막기 jta.setEditable(false); // 접속자 리스트 width 제한 clientList.setFixedCellWidth(d.width / 3); // 입력 창 f.add(name, "West"); f.add(jtf, "Center"); f.add(textin, "East"); // 접속자 확인창 s.add(new JLabel("접속자", (int) CENTER_ALIGNMENT), "North"); s.add(list, "Center"); // clientList.setEditable(false); // 메인 창 m.add(jsp, "Center"); m.add(s, "East"); // 프레임 설정 add(h, "North"); add(m, "Center"); add(f, "South"); // 로그인 다이얼로그 jd = new JDialog(); jd.setTitle("채팅 로그인"); jd.add(login); jd.setSize(200, 200); Dimension dd = jd.getSize(); jd.setLocation(screenSize.width / 2 - (dd.width / 2), screenSize.height / 2 - (dd.height / 2)); jd.setVisible(true); // 로그인창 JPanel lm = new JPanel(new GridLayout(4, 1)); lm.add(lid); lm.add(new Label()); lm.add(lpw); lm.add(new Label()); JPanel bt = new JPanel(); bt.add(conf); bt.add(join); login.add(new Label(), "North"); login.add(new Label(), "West"); login.add(new Label(), "East"); login.add(lm, "Center"); login.add(bt, "South"); // 창의 위치, 보임, EXIT 단추 활성화. setLocation(screenSize.width / 2 - (d.width / 2), screenSize.height / 2 - (d.height / 2)); setVisible(false); setDefaultCloseOperation(EXIT_ON_CLOSE); }
/** * Open the config dialog, send the config update to the robot, save it for future, and refresh * the preview tab. */ public void UpdateConfig() { final JDialog driver = new JDialog(mainframe, "Configure Limits", true); driver.setLayout(new GridBagLayout()); final JTextField mtop = new JTextField(String.valueOf(limit_top)); final JTextField mbottom = new JTextField(String.valueOf(limit_bottom)); final JTextField mleft = new JTextField(String.valueOf(limit_left)); final JTextField mright = new JTextField(String.valueOf(limit_right)); final JTextField ptop = new JTextField(String.valueOf(paper_top)); final JTextField pbottom = new JTextField(String.valueOf(paper_bottom)); final JTextField pleft = new JTextField(String.valueOf(paper_left)); final JTextField pright = new JTextField(String.valueOf(paper_right)); final JButton cancel = new JButton("Cancel"); final JButton save = new JButton("Save"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 3; c.gridy = 0; driver.add(mtop, c); c.gridx = 3; c.gridy = 5; driver.add(mbottom, c); c.gridx = 0; c.gridy = 3; driver.add(mleft, c); c.gridx = 5; c.gridy = 3; driver.add(mright, c); c.gridx = 3; c.gridy = 1; driver.add(ptop, c); c.gridx = 3; c.gridy = 4; driver.add(pbottom, c); c.gridx = 1; c.gridy = 3; driver.add(pleft, c); c.gridx = 4; c.gridy = 3; driver.add(pright, c); c.gridx = 4; c.gridy = 6; driver.add(save, c); c.gridx = 5; c.gridy = 6; driver.add(cancel, c); Dimension s = ptop.getPreferredSize(); s.width = 80; ptop.setPreferredSize(s); pbottom.setPreferredSize(s); pleft.setPreferredSize(s); pright.setPreferredSize(s); mtop.setPreferredSize(s); mbottom.setPreferredSize(s); mleft.setPreferredSize(s); mright.setPreferredSize(s); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { paper_top = Float.valueOf(ptop.getText()); paper_bottom = Float.valueOf(pbottom.getText()); paper_right = Float.valueOf(pright.getText()); paper_left = Float.valueOf(pleft.getText()); limit_top = Float.valueOf(mtop.getText()); limit_bottom = Float.valueOf(mbottom.getText()); limit_right = Float.valueOf(mright.getText()); limit_left = Float.valueOf(mleft.getText()); previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right); previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right); SetRecentPaperSize(); SaveConfig(); SendConfig(); driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); SendLineToRobot("M114"); // "where" command driver.pack(); driver.setVisible(true); }
@Override public void actionPerformed(ActionEvent e) { licence_text = new String( "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see <http://www.gnu.org/licenses/>.\n" + "\n\n\n"); try { InputStream ips = new FileInputStream(getClass().getResource("COPYING").getPath()); InputStreamReader ipsr = new InputStreamReader(ips); BufferedReader br = new BufferedReader(ipsr); String line; while ((line = br.readLine()) != null) { licence_text += line + '\n'; } br.close(); } catch (Exception e1) { } Dimension dimension = new Dimension(600, 400); JDialog licence = new JDialog(memento, "Licence"); JTextPane text_pane = new JTextPane(); text_pane.setEditable(false); text_pane.setPreferredSize(dimension); text_pane.setSize(dimension); StyledDocument doc = text_pane.getStyledDocument(); Style justified = doc.addStyle( "justified", StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)); StyleConstants.setAlignment(justified, StyleConstants.ALIGN_JUSTIFIED); try { doc.insertString(0, licence_text, justified); } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text into text pane."); } Style logicalStyle = doc.getLogicalStyle(0); doc.setParagraphAttributes(0, licence_text.length(), justified, false); doc.setLogicalStyle(0, logicalStyle); JScrollPane paneScrollPane = new JScrollPane(text_pane); paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setPreferredSize(dimension); paneScrollPane.setMinimumSize(dimension); JPanel pan = new JPanel(); LayoutManager layout = new BorderLayout(); pan.setLayout(layout); pan.add(new JScrollPane(paneScrollPane), BorderLayout.CENTER); JButton close = new JButton("Fermer"); close.addActionListener(new ButtonCloseActionListener(licence)); JPanel button_panel = new JPanel(); FlowLayout button_panel_layout = new FlowLayout(FlowLayout.RIGHT, 20, 20); button_panel.setLayout(button_panel_layout); button_panel.add(close); pan.add(button_panel, BorderLayout.SOUTH); licence.add(pan); licence.pack(); licence.setLocationRelativeTo(memento); licence.setVisible(true); }
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); }
protected void JogMotors() { JDialog driver = new JDialog(mainframe, "Jog Motors", true); driver.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); final JButton buttonAneg = new JButton("IN"); final JButton buttonApos = new JButton("OUT"); final JCheckBox m1i = new JCheckBox("Invert", m1invert); final JButton buttonBneg = new JButton("IN"); final JButton buttonBpos = new JButton("OUT"); final JCheckBox m2i = new JCheckBox("Invert", m2invert); c.gridx = 0; c.gridy = 0; driver.add(new JLabel("L"), c); c.gridx = 0; c.gridy = 1; driver.add(new JLabel("R"), c); c.gridx = 1; c.gridy = 0; driver.add(buttonAneg, c); c.gridx = 1; c.gridy = 1; driver.add(buttonBneg, c); c.gridx = 2; c.gridy = 0; driver.add(buttonApos, c); c.gridx = 2; c.gridy = 1; driver.add(buttonBpos, c); c.gridx = 3; c.gridy = 0; driver.add(m1i, c); c.gridx = 3; c.gridy = 1; driver.add(m2i, c); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == buttonApos) SendLineToRobot("D00 L100"); if (subject == buttonAneg) SendLineToRobot("D00 L-100"); if (subject == buttonBpos) SendLineToRobot("D00 R100"); if (subject == buttonBneg) SendLineToRobot("D00 R-100"); SendLineToRobot("M114"); } }; ActionListener invertButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { m1invert = m1i.isSelected(); m2invert = m2i.isSelected(); SaveConfig(); SendConfig(); } }; buttonApos.addActionListener(driveButtons); buttonAneg.addActionListener(driveButtons); buttonBpos.addActionListener(driveButtons); buttonBneg.addActionListener(driveButtons); m1i.addActionListener(invertButtons); m2i.addActionListener(invertButtons); SendLineToRobot("M114"); driver.pack(); driver.setVisible(true); }
/** * Creates a dialog where the user can specify the location of the database,including the type of * network connection (if this is a networked client)and IP address and port number; or search and * select the database on a local drive if this is a standalone client. * * @param parent Defines the Component that is to be the parent of this dialog box. For * information on how this is used, see <code>JOptionPane</code> * @param connectionMode Specifies the type of connection (standalone or networked) * @see JOptionPane */ public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) { configOptions = (new ConfigOptions(connectionMode)); configOptions.getObservable().addObserver(this); // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); // the port and connection type are irrelevant in standalone mode if (connectionMode == ApplicationMode.STANDALONE_CLIENT) { validPort = true; validCnx = true; networkType = ConnectionType.DIRECT; location = config.getParameter(SavedConfiguration.DATABASE_LOCATION); } else { // there may not be a network connectivity type defined and, if // not, we do not set a default - force the user to make a choice // the at least for the first time they run this. String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE); if (tmp != null) { try { networkType = ConnectionType.valueOf(tmp); configOptions.setNetworkConnection(networkType); validCnx = true; } catch (IllegalArgumentException e) { log.warning("Unknown connection type: " + networkType); } } // there is always at least a default port number, so we don't have // to validate this. port = config.getParameter(SavedConfiguration.SERVER_PORT); configOptions.setPortNumberText(port); validPort = true; location = config.getParameter(SavedConfiguration.SERVER_ADDRESS); } // there may not be a default database location, so we had better // validate before using the returned value. if (location != null) { configOptions.setLocationFieldText(location); validDb = true; } options = new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); connectButton.setActionCommand(CONNECT); connectButton.addActionListener(this); boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); exitButton.setActionCommand(EXIT); exitButton.addActionListener(this); options.setOptions(new Object[] {connectButton, exitButton}); dialog = options.createDialog(parent, TITLE); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(this); dialog.setVisible(true); }
/** Popup the Manager Dialog */ public void show() { if (viewDialog != null) { viewDialog.setVisible(true); } }
/** Close this widget */ public void close() { if (viewDialog != null) { viewDialog.setVisible(false); } }
MyCustomizableGUI() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); textField = new JTextField(20); buttonPref = new JButton("Preferences"); this.add(textField); this.add(buttonPref); buttonPref.addActionListener(evt -> prefDialog.setVisible(true)); frame = new JFrame("My text editor"); frame.setContentPane(this); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // Preferences dialog box prefDialog = new JDialog(frame, "Dialog", true); prefDialog.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3, 2)); JPanel p2 = new JPanel(); p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); buttonSave = new JButton("Save"); buttonCancel = new JButton("Cancel"); buttonSave.addActionListener( evtSave -> { String fontChosen; int fontSizeChosen; prefDialog.setVisible(false); if ((String) color.getSelectedItem() == "Red") { textField.setForeground(Color.red); } else if ((String) color.getSelectedItem() == "Green") { textField.setForeground(Color.green); } else if ((String) color.getSelectedItem() == "Blue") { textField.setForeground(Color.blue); } else if ((String) color.getSelectedItem() == "Cyan") { textField.setForeground(Color.cyan); } else if ((String) color.getSelectedItem() == "Magenta") { textField.setForeground(Color.magenta); } else if ((String) color.getSelectedItem() == "Yellow") { textField.setForeground(Color.yellow); } else if ((String) color.getSelectedItem() == "Black") { textField.setForeground(Color.black); } fontChosen = (String) font.getSelectedItem(); fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem()); textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen)); UserPreferences userPrefs = new UserPreferences(); userPrefs.setColor((String) color.getSelectedItem()); userPrefs.setFont(fontChosen); userPrefs.setFontSize(fontSizeChosen); try (FileOutputStream fileOut = new FileOutputStream("preferences.ser"); ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) { objectOut.writeObject(userPrefs); } catch (IOException ioe) { System.out.println("I/O error: " + ioe.getMessage()); } }); buttonCancel.addActionListener(evt -> prefDialog.setVisible(false)); colorLabel = new JLabel("Color:"); fontLabel = new JLabel("Font:"); fontSizeLabel = new JLabel("Font size:"); color = new JComboBox(colorList); font = new JComboBox(fontList); fontSize = new JComboBox(fontSizeList); p1.add(colorLabel); p1.add(color); p1.add(fontLabel); p1.add(font); p1.add(fontSizeLabel); p1.add(fontSize); p2.add(buttonCancel); p2.add(buttonSave); prefDialog.add(BorderLayout.NORTH, p1); prefDialog.add(BorderLayout.SOUTH, p2); prefDialog.pack(); }
public void run() { while (connected) { try { Object obj = in.readObject(); if (obj.toString().equals("-101")) { connected = false; in.close(); out.close(); socket.close(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Disconnected from server. Please Restart", "Error:", JOptionPane.PLAIN_MESSAGE); try { m.stop(); } catch (Exception w) { } } }); } else if (obj.toString().split("::")[0].equals("broadcast")) { // System.out.println("braodcast received"); bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("chat")) { // System.out.println("chat received: // "+obj.toString().substring(obj.toString().indexOf("::")+2)); cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("rankings")) { String hhh = obj.toString().split("::")[1]; final JDialog jd = new JDialog(); jd.setUndecorated(false); JPanel pan = new JPanel(new BorderLayout()); JLabel ppp = new JLabel(); ppp.setFont(new Font("Arial", Font.BOLD, 20)); ppp.setText( "<html><pre>Thanks for playing !!!<br/>1st: " + hhh.split(":")[0] + "<br/>2nd: " + hhh.split(":")[1] + "<br/>3rd: " + hhh.split(":")[2] + "</pre></html>"); pan.add(ppp, BorderLayout.CENTER); JButton ok = new JButton("Ok"); ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jd.setVisible(false); try { m.stop(); } catch (Exception w) { } } }); pan.add(ok, BorderLayout.SOUTH); jd.setContentPane(pan); jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL); jd.pack(); jd.setLocationRelativeTo(null); jd.setVisible(true); } else if (obj.toString().split("::")[0].equals("rank")) { rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else { User hhh = null; try { hhh = (User) obj; /*if(usrD==1) { reply=obj; ccl.interrupt(); } else*/ { try { m.ur.changeData((User) obj); } catch (Exception w) { try { maain.ur.changeData((User) obj); } catch (Exception ppp) { ppp.printStackTrace(); } } } } catch (Exception p) { int iid = -1; try { iid = Integer.parseInt(obj.toString()); obj = in.readObject(); if (obj.toString().equals("-102")) { // ccl.interrupt(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE); } }); } // Thread th = ((Thread)rev.remove(iid)); rev2.put(iid, obj); // System.out.println("Put: "+iid+" : "+obj.toString()+" : // "+Thread.currentThread()); // th.interrupt(); // ccl.interrupt(); } catch (Exception ppp) { /*ppp.printStackTrace();*/ System.out.println( "Shit: " + iid + " : " + obj.toString() + " : " + Thread.currentThread()); } } } try { Thread.sleep(500); } catch (Exception n) { } } catch (Exception m) { } } }
protected boolean exportApplicationPrompt() throws IOException, SketchException { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalStrut(6)); // Box panel = Box.createVerticalBox(); // Box labelBox = Box.createHorizontalBox(); // String msg = "<html>Click Export to Application to create a standalone, " + // "double-clickable application for the selected plaforms."; // String msg = "Export to Application creates a standalone, \n" + // "double-clickable application for the selected plaforms."; String line1 = "Export to Application creates double-clickable,"; String line2 = "standalone applications for the selected plaforms."; JLabel label1 = new JLabel(line1, SwingConstants.CENTER); JLabel label2 = new JLabel(line2, SwingConstants.CENTER); label1.setAlignmentX(Component.LEFT_ALIGNMENT); label2.setAlignmentX(Component.LEFT_ALIGNMENT); // label1.setAlignmentX(); // label2.setAlignmentX(0); panel.add(label1); panel.add(label2); int wide = label2.getPreferredSize().width; panel.add(Box.createVerticalStrut(12)); final JCheckBox windowsButton = new JCheckBox("Windows"); // windowsButton.setMnemonic(KeyEvent.VK_W); windowsButton.setSelected(Preferences.getBoolean("export.application.platform.windows")); windowsButton.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean( "export.application.platform.windows", windowsButton.isSelected()); } }); final JCheckBox macosxButton = new JCheckBox("Mac OS X"); // macosxButton.setMnemonic(KeyEvent.VK_M); macosxButton.setSelected(Preferences.getBoolean("export.application.platform.macosx")); macosxButton.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean("export.application.platform.macosx", macosxButton.isSelected()); } }); final JCheckBox linuxButton = new JCheckBox("Linux"); // linuxButton.setMnemonic(KeyEvent.VK_L); linuxButton.setSelected(Preferences.getBoolean("export.application.platform.linux")); linuxButton.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean("export.application.platform.linux", linuxButton.isSelected()); } }); JPanel platformPanel = new JPanel(); // platformPanel.setLayout(new BoxLayout(platformPanel, BoxLayout.X_AXIS)); platformPanel.add(windowsButton); platformPanel.add(Box.createHorizontalStrut(6)); platformPanel.add(macosxButton); platformPanel.add(Box.createHorizontalStrut(6)); platformPanel.add(linuxButton); platformPanel.setBorder(new TitledBorder("Platforms")); // Dimension goodIdea = new Dimension(wide, platformPanel.getPreferredSize().height); // platformPanel.setMaximumSize(goodIdea); wide = Math.max(wide, platformPanel.getPreferredSize().width); platformPanel.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(platformPanel); // Box indentPanel = Box.createHorizontalBox(); // indentPanel.add(Box.createHorizontalStrut(new JCheckBox().getPreferredSize().width)); final JCheckBox showStopButton = new JCheckBox("Show a Stop button"); // showStopButton.setMnemonic(KeyEvent.VK_S); showStopButton.setSelected(Preferences.getBoolean("export.application.stop")); showStopButton.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean("export.application.stop", showStopButton.isSelected()); } }); showStopButton.setEnabled(Preferences.getBoolean("export.application.fullscreen")); showStopButton.setBorder(new EmptyBorder(3, 13, 6, 13)); // indentPanel.add(showStopButton); // indentPanel.setAlignmentX(Component.LEFT_ALIGNMENT); final JCheckBox fullScreenButton = new JCheckBox("Full Screen (Present mode)"); // fullscreenButton.setMnemonic(KeyEvent.VK_F); fullScreenButton.setSelected(Preferences.getBoolean("export.application.fullscreen")); fullScreenButton.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean sal = fullScreenButton.isSelected(); Preferences.setBoolean("export.application.fullscreen", sal); showStopButton.setEnabled(sal); } }); fullScreenButton.setBorder(new EmptyBorder(3, 13, 3, 13)); JPanel optionPanel = new JPanel(); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS)); optionPanel.add(fullScreenButton); optionPanel.add(showStopButton); // optionPanel.add(indentPanel); optionPanel.setBorder(new TitledBorder("Options")); wide = Math.max(wide, platformPanel.getPreferredSize().width); // goodIdea = new Dimension(wide, optionPanel.getPreferredSize().height); optionPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // optionPanel.setMaximumSize(goodIdea); panel.add(optionPanel); Dimension good; // label1, label2, platformPanel, optionPanel good = new Dimension(wide, label1.getPreferredSize().height); label1.setMaximumSize(good); good = new Dimension(wide, label2.getPreferredSize().height); label2.setMaximumSize(good); good = new Dimension(wide, platformPanel.getPreferredSize().height); platformPanel.setMaximumSize(good); good = new Dimension(wide, optionPanel.getPreferredSize().height); optionPanel.setMaximumSize(good); // JPanel actionPanel = new JPanel(); // optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.X_AXIS)); // optionPanel.add(Box.createHorizontalGlue()); // final JDialog frame = new JDialog(editor, "Export to Application"); // JButton cancelButton = new JButton("Cancel"); // cancelButton.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // frame.dispose(); // return false; // } // }); // Add the buttons in platform-specific order // if (PApplet.platform == PConstants.MACOSX) { // optionPanel.add(cancelButton); // optionPanel.add(exportButton); // } else { // optionPanel.add(exportButton); // optionPanel.add(cancelButton); // } String[] options = {"Export", "Cancel"}; final JOptionPane optionPane = new JOptionPane( panel, JOptionPane.PLAIN_MESSAGE, // JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]); final JDialog dialog = new JDialog(this, "Export Options", true); dialog.setContentPane(optionPane); optionPane.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) { // If you were going to check something // before closing the window, you'd do // it here. dialog.setVisible(false); } } }); dialog.pack(); dialog.setResizable(false); Rectangle bounds = getBounds(); dialog.setLocation( bounds.x + (bounds.width - dialog.getSize().width) / 2, bounds.y + (bounds.height - dialog.getSize().height) / 2); dialog.setVisible(true); Object value = optionPane.getValue(); if (value.equals(options[0])) { return jmode.handleExportApplication(sketch); } else if (value.equals(options[1]) || value.equals(new Integer(-1))) { // closed window by hitting Cancel or ESC statusNotice("Export to Application canceled."); } return false; }
/** Open the config dialog, update the paper size, refresh the preview tab. */ public void Drive() { JDialog driver = new JDialog(mainframe, "Manual Control", true); driver.setLayout(new GridBagLayout()); JButton find = new JButton("FIND HOME"); JButton home = new JButton("GO HOME"); JButton center = new JButton("THIS IS HOME"); JButton up1 = new JButton("Y1"); JButton up10 = new JButton("Y10"); JButton up100 = new JButton("Y100"); JButton down1 = new JButton("Y-1"); JButton down10 = new JButton("Y-10"); JButton down100 = new JButton("Y-100"); JButton left1 = new JButton("X-1"); JButton left10 = new JButton("X-10"); JButton left100 = new JButton("X-100"); JButton right1 = new JButton("X1"); JButton right10 = new JButton("X10"); JButton right100 = new JButton("X100"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 3; c.gridy = 0; driver.add(up100, c); c.gridx = 3; c.gridy = 1; driver.add(up10, c); c.gridx = 3; c.gridy = 2; driver.add(up1, c); c.gridx = 3; c.gridy = 4; driver.add(down1, c); c.gridx = 3; c.gridy = 5; driver.add(down10, c); c.gridx = 3; c.gridy = 6; driver.add(down100, c); c.gridx = 0; c.gridy = 3; driver.add(left100, c); c.gridx = 1; c.gridy = 3; driver.add(left10, c); c.gridx = 2; c.gridy = 3; driver.add(left1, c); c.gridx = 4; c.gridy = 3; driver.add(right1, c); c.gridx = 5; c.gridy = 3; driver.add(right10, c); c.gridx = 6; c.gridy = 3; driver.add(right100, c); c.gridx = 3; c.gridy = 3; driver.add(home, c); c.gridx = 6; c.gridy = 0; driver.add(center, c); c.gridx = 6; c.gridy = 1; driver.add(find, c); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); JButton b = (JButton) subject; String t = b.getText(); if (t == "GO HOME") { GoHome(); SendLineToRobot("M114"); } else if (t == "FIND HOME") { SendLineToRobot("G28"); } else if (t == "THIS IS HOME") { SendLineToRobot("TELEPORT XO YO"); } else { SendLineToRobot("G91"); SendLineToRobot("G00 " + b.getText()); SendLineToRobot("G90"); SendLineToRobot("M114"); } } }; up1.addActionListener(driveButtons); up10.addActionListener(driveButtons); up100.addActionListener(driveButtons); down1.addActionListener(driveButtons); down10.addActionListener(driveButtons); down100.addActionListener(driveButtons); left1.addActionListener(driveButtons); left10.addActionListener(driveButtons); left100.addActionListener(driveButtons); right1.addActionListener(driveButtons); right10.addActionListener(driveButtons); right100.addActionListener(driveButtons); center.addActionListener(driveButtons); home.addActionListener(driveButtons); find.addActionListener(driveButtons); SendLineToRobot("M114"); driver.pack(); driver.setVisible(true); }