/** * This method starts the GUI. * * @throws CoapException Thrown, if the connection to obix via CoAP fails. */ public void runGui() throws CoapException { this.lobby = obixChannel.getLobby(obixChannel.getLobbyUri()); // Create and set up the window. mainFrame = new JFrame("ObixConnector at " + obixChannel.getBaseUri() + ": " + obixChannel.getPort()); mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); mainFrame.setUndecorated(false); mainFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { close(); } }); Container contentPane = mainFrame.getContentPane(); // Create and set up the content pane. this.addComponentToPane(contentPane); // Display the window. mainFrame.pack(); executor.execute(updateThread); connector.addRunAndStopAble(updateThread); mainFrame.setVisible(true); }
public static void main(String[] args) { JFrame gameWindow = new JFrame("Tic Tac Toe"); gameWindow.add(new TicTacToeGame()); gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameWindow.pack(); gameWindow.setVisible(true); }
public RemoveFrame() { frame = new JFrame("Select Files you wish to Remove from Drive"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getRootPane().setDefaultButton(confirm); try { files = DriveList.list(); } catch (IOException e) { files = new ArrayList<File>(); } confirm = new JButton("Remove"); quit = new JButton("Cancel"); confirm.addActionListener(this); quit.addActionListener(this); frame.setLayout(new BorderLayout()); checkPanel = new JPanel(); control = new JPanel(); control.setLayout(new GridLayout(1, 2)); control.add(confirm); control.add(quit); frame.add(control, BorderLayout.SOUTH); drawCheckPanel(); frame.add(checkPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
public void go() throws IOException { // DefaultRouteTable route = new DefaultRouteTable(); // System.out.println(route.routeInfo()); // route.routeInfo(); totalSize = Toolkit.getDefaultToolkit().getScreenSize(); // getting screen size int width = totalSize.width; int height = totalSize.height; frame = new JFrame(); // creating frame frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { FileInput data = null; try { data = new FileInput("input.txt"); } catch (Exception e) { } String[][] origRoutes = convertArrayListTo2DArray(data.routeArrayList(data.routesToken), 1); String[][] routesList = Main.convertArrayListTo2DArray(routesInfo, 1); Main.changesCheck(origRoutes, routesList); } }); frame.setTitle("Air Route Planner"); frame.add(Panels()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize((width * 3 / 4), (height * 3 / 4)); frame.setJMenuBar(menuBar()); frame.setResizable(false); frame.setVisible(true); frame.setLocationRelativeTo(null); }
/** *********************************************************************** */ private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); // give JFrame nice decorations JFrame frame = new JFrame("Java GUI"); // create the JFrame frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); // set up the JFrame to end the program when it closes Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); ColorBars drawingPanel = new ColorBars(); // set up the panel to draw in drawingPanel.setBackground(Color.BLACK); // the the background to black drawingPanel.btnDraw = new JButton("Click me"); // instantiate a swing button drawingPanel.btnDraw.addActionListener(drawingPanel); // register the panel with the button drawingPanel.btnClear = new JButton("Clear Screen"); drawingPanel.btnClear.addActionListener(drawingPanel); Panel buttonPanel = new Panel(); // instantiate the panel for buttons buttonPanel.add(drawingPanel.btnDraw); // add the swing button the the button panel buttonPanel.add(drawingPanel.btnClear); c.add( drawingPanel, BorderLayout.CENTER); // add the drawing panel to the frame (take up the entire frame) c.add(buttonPanel, BorderLayout.SOUTH); // add the button panel to the bottom of the frame frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // set the window to maximized frame.setSize(600, 400); // set the frame size (in case user un-maximizes frame.setVisible(true); // display the frame }
/** * Init JWhiteBoard interface * * @throws Exception */ public void go() throws Exception { if (!noChannel && !useState) channel.connect(groupName); mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); drawPanel = new DrawPanel(useState); drawPanel.setBackground(backgroundColor); subPanel = new JPanel(); mainFrame.getContentPane().add("Center", drawPanel); clearButton = new JButton("Clean"); clearButton.setFont(defaultFont); clearButton.addActionListener(this); leaveButton = new JButton("Exit"); leaveButton.setFont(defaultFont); leaveButton.addActionListener(this); subPanel.add("South", clearButton); subPanel.add("South", leaveButton); mainFrame.getContentPane().add("South", subPanel); mainFrame.setBackground(backgroundColor); clearButton.setForeground(Color.blue); leaveButton.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); if (!noChannel && useState) { channel.connect(groupName, null, stateTimeout); } mainFrame.setVisible(true); }
private Game() { // Top-level frame final JFrame frame = new JFrame("Falling Blocks"); frame.setLocation(200, 50); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Main playing area final TetrisCourt court = new TetrisCourt(); frame.add(court, BorderLayout.CENTER); // Reset button final JPanel panel = new JPanel(); frame.add(panel, BorderLayout.NORTH); final JButton reset = new JButton("Reset"); reset.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { court.reset(); } }); panel.add(reset); // Put the frame on the screen frame.pack(); frame.setVisible(true); // Start the game running court.reset(); }
public static void main(String[] args) { JFrame frame = new JFrame("startbooking1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new startbooking1()); frame.pack(); frame.setVisible(true); }
public void newframe() { JFrame frame = new JFrame("Cab Service "); frame.setSize(800, 600); frame.setVisible(true); // frame.setBackground(Color.CYAN); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton jb = new JButton("Set Name of Places "); jb.setBounds(100, 100, 20, 50); JPanel jp = new JPanel(); jp.setBackground(Color.gray); jp.add(jb); frame.add(jp); JPanel jp1 = new JPanel(); jp1.setBackground(Color.gray); frame.add(jp1); frame.add(jp); jb.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { CreateFrame(); } catch (IOException ex) { Logger.getLogger(SetMap.class.getName()).log(Level.SEVERE, null, ex); } } }); }
private MainPanel(final JFrame frame) { super(); add(check); setPreferredSize(new Dimension(320, 240)); if (!SystemTray.isSupported()) { frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); return; } frame.addWindowListener( new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { if (check.isSelected()) { e.getWindow().dispose(); } } }); // or // frame.addWindowStateListener(new WindowStateListener() { // @Override public void windowStateChanged(WindowEvent e) { // if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) { // e.getWindow().dispose(); // } // } // }); final SystemTray tray = SystemTray.getSystemTray(); Dimension d = tray.getTrayIconSize(); BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height); final PopupMenu popup = new PopupMenu(); final TrayIcon icon = new TrayIcon(image, "TRAY", popup); MenuItem item1 = new MenuItem("OPEN"); item1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(true); } }); MenuItem item2 = new MenuItem("EXIT"); item2.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tray.remove(icon); frame.dispose(); // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } }); popup.add(item1); popup.add(item2); try { tray.add(icon); } catch (AWTException e) { e.printStackTrace(); } }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame .getContentPane() .setLayout( new FormLayout( new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.LABEL_COMPONENT_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormFactory.LINE_GAP_ROWSPEC, })); JPanel panel = new JPanel(); frame.getContentPane().add(panel, "2, 2, fill, fill"); openDialog = new FileDialog(this, "Open File", FileDialog.LOAD); JButton btnCharger = new JButton("Charger une partie"); btnCharger.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { openDialog.setVisible(true); try { String dir = openDialog.getDirectory() + openDialog.getFile(); Utilitaire.writeln(dir, textArea); jeu = new Kakuro(frame, dir); jeu.setVisible(true); } catch (NullPointerException point) { } } }); panel.add(btnCharger); JButton btnNvlPartie = new JButton("Nouvelle Partie"); panel.add(btnNvlPartie); btnNvlPartie.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Random list = new Random(); int seed = list.nextInt(); new Utilitaire(Utilitaire.x, Utilitaire.y, seed); jeu = new Kakuro(frame); jeu.setVisible(true); } }); textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); frame.getContentPane().add(scrollPane, "2, 4, fill, fill"); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("Automated File Mover"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { try { FileOutputStream f_out = new FileOutputStream(LOG_DIRECTORY + "save.data"); // Write object with ObjectOutputStream ObjectOutputStream obj_out = new ObjectOutputStream(f_out); // Write object out to disk obj_out.writeObject(directoryList); obj_out.writeObject(ERROR_LOG_NAME); obj_out.writeObject(MOVE_LOG_NAME); obj_out.flush(); obj_out.close(); printer.printError(LOG_DIRECTORY); } catch (IOException x) { printer.printError(x.toString()); } } }); // Create and set up the content pane. JComponent newContentPane = new fileBackupProgram(frame); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final PasswordDialog addPassword = new PasswordDialog(frame); addPassword.setVisible(true); System.exit(0); }
void makeFrame() { JPanel p = new JPanel(); p.setBackground(Color.blue); p.setLayout(new BorderLayout(0, 0)); p.setBorder(new EmptyBorder(0, GAP, GAP, GAP)); days.setFont(BIG); days.setForeground(COLOR); p.add(days, "North"); left.setFont(NORM); left.setForeground(COLOR); p.add(left, "South"); JFrame f = new JFrame("Sayaç"); // a window f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(p); setDate(); f.pack(); // minimal size f.setVisible(true); // show f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { stop(); } }); }
public static void main(String[] args) { final JPopupMenu menu = new JPopupMenu(); menu.setLayout(new GridLayout(0, 3, 5, 5)); final MenuedButton button = new MenuedButton("Icons", menu); for (int i = 0; i < 9; i++) { // replace "print.gif" with your own image final JLabel label = new JLabel("" + i); // new ImageIcon("resources/images/print.gif") ); label.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { button.getMainButton().setIcon(label.getIcon()); menu.setVisible(false); } }); menu.add(label); } JFrame frame = new JFrame("Button Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new JLabel("Click Arrow Button To Show Popup"), BorderLayout.NORTH); frame.getContentPane().add(button, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
// Add a test case to testBox and tests array. private void addTest() { // Set up the frame for the file chooser. final JFrame appframe = new JFrame("Select Application"); appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container contentPane = appframe.getContentPane(); JFileChooser fileChooser = new JFileChooser("."); // Only let you select directories and add chooser to pane. fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); contentPane.add(fileChooser, BorderLayout.CENTER); // Make a new action listener for the file chooser. ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { // Get the information to check if the file chosen is valid. JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource(); String command = actionEvent.getActionCommand(); // If the user cancels selecting a program. if (command.equals(JFileChooser.CANCEL_SELECTION)) { appframe.setVisible(false); appframe.dispose(); return; } // If the file chosen is valid. if (command.equals(JFileChooser.APPROVE_SELECTION)) { // Retrieve the selected file and ask for the main class name. File f = theFileChooser.getSelectedFile(); // Obtain the file URL. String fileURL = null; fileURL = f.getAbsolutePath(); // Add a checkbox to the testing check pane. JCheckBox newTest = new JCheckBox(fileURL, true); testBox.setEditable(true); testBox.add(newTest); testBox.repaint(); testBox.setEditable(false); // Add the test to the list of tests. tests.add(newTest); // Make the file chooser disappear. appframe.setVisible(false); appframe.dispose(); } } }; // Add the action listener created above to file chooser, display it. fileChooser.addActionListener(actionListener); appframe.pack(); appframe.setVisible(true); }
// Initialize all the GUI components and display the frame private static void initGUI() { // Set up the status bar statusField = new JLabel(); statusField.setText(statusMessages[DISCONNECTED]); statusColor = new JTextField(1); statusColor.setBackground(Color.red); statusColor.setEditable(false); statusBar = new JPanel(new BorderLayout()); statusBar.add(statusColor, BorderLayout.WEST); statusBar.add(statusField, BorderLayout.CENTER); // Set up the options pane JPanel optionsPane = initOptionsPane(); // Set up the chat pane JPanel chatPane = new JPanel(new BorderLayout()); chatText = new JTextArea(10, 20); chatText.setLineWrap(true); chatText.setEditable(false); chatText.setForeground(Color.blue); JScrollPane chatTextPane = new JScrollPane( chatText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chatLine = new JTextField(); chatLine.setEnabled(false); chatLine.addActionListener( new ActionAdapter() { public void actionPerformed(ActionEvent e) { String s = chatLine.getText(); if (!s.equals("")) { appendToChatBox("OUTGOING: " + s + "\n"); chatLine.selectAll(); // Send the string sendString(s); } } }); chatPane.add(chatLine, BorderLayout.SOUTH); chatPane.add(chatTextPane, BorderLayout.CENTER); chatPane.setPreferredSize(new Dimension(200, 200)); // Set up the main pane JPanel mainPane = new JPanel(new BorderLayout()); mainPane.add(statusBar, BorderLayout.SOUTH); mainPane.add(optionsPane, BorderLayout.WEST); mainPane.add(chatPane, BorderLayout.CENTER); // Set up the main frame mainFrame = new JFrame("Simple TCP Chat"); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setContentPane(mainPane); mainFrame.setSize(mainFrame.getPreferredSize()); mainFrame.setLocation(200, 200); mainFrame.pack(); mainFrame.setVisible(true); }
public static void main(String args[]) { JFrame frame = new CopyFileToTable(); frame.setTitle("CopyFileToTable"); frame.setSize(700, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public void editContactWindow() { editWindow = new JFrame("Edit Contacts"); editWindow.setLayout(new FlowLayout()); // Add List editWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); editWindow.pack(); editWindow.setVisible(true); }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
/** Main method */ public static void main(String[] args) { JFrame frame = new SimpleEventDemo2(); frame.setTitle("SimpleEventDemo2"); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(100, 80); frame.setVisible(true); }
// 建立元件、將元件加入視窗、顯示視窗的方法 public void init() { myframe.addKeyListener(this); // 設定按鍵事件的傾聽者 myframe.getContentPane().add(whatkey); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myframe.setSize(240, 120); myframe.setVisible(true); }
// Debugging public static void main(String[] args) { JFrame win = new JFrame(); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ContactListUI clUI = new ContactListUI(); win.add(clUI); win.pack(); win.setVisible(true); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GamePanel game = new GamePanel(); frame.add(game); frame.setVisible(true); }
// Constructor public FileWindow() { myWindow = new JFrame("New File"); myWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container contentPane = myWindow.getContentPane(); contentPane.setLayout(new BorderLayout()); saveButton = new JButton("Save File"); saveButton.setSelected(false); saveButton.setActionCommand("save"); saveButton.setMnemonic('S'); // saveButton.addActionListener(new ScriptWindowButtonListener()); clearButton = new JButton("Clear Contents"); clearButton.setSelected(false); clearButton.setActionCommand("clear"); clearButton.setMnemonic('B'); clearButton.addActionListener(new ScriptWindowButtonListener()); cancelButton = new JButton("Quit"); cancelButton.setSelected(false); cancelButton.setActionCommand("quit"); cancelButton.setMnemonic('Q'); cancelButton.addActionListener(new ScriptWindowButtonListener()); // loadButton = new JButton("Load Script"); // loadButton.setSelected(false); // loadButton.setActionCommand("load"); // loadButton.setMnemonic('L'); // loadButton.addActionListener(new ScriptWindowButtonListener()); // // runButton = new JButton("Run Script"); // runButton.setSelected(false); // runButton.setActionCommand("run"); // runButton.setMnemonic('L'); // runButton.addActionListener(new ScriptWindowButtonListener()); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(1, 0)); // buttonPanel.add(runButton); buttonPanel.add(saveButton); // buttonPanel.add(loadButton); buttonPanel.add(clearButton); // buttonPanel.add(cancelButton); fileChooser = new JFileChooser(); scriptArea = new JTextArea(35, 30); JScrollPane scroller = new JScrollPane(scriptArea); textHolder = new JPanel(); textHolder.setLayout(new BorderLayout()); textHolder.add(scroller, BorderLayout.CENTER); contentPane.add(buttonPanel, BorderLayout.NORTH); contentPane.add(textHolder, BorderLayout.CENTER); myWindow.pack(); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 500); frame.setTitle("Breakout"); frame.setResizable(false); frame.add(new GamePanel()); frame.setVisible(true); }
/** Main method */ public static void main(String[] args) { JFrame frame = new JFrame("ClockAnimation"); ClockAnimation clock = new ClockAnimation(); frame.add(clock); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); }
public static void main(String args[]) { JFrame jf = new JFrame(); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BackPanel bp = new BackPanel(); jf.add(bp); jf.setSize(bp.WIDTH, bp.HEIGHT); jf.setResizable(false); jf.setVisible(true); }
/** Method to create and initialize the picture frame */ private void createAndInitPictureFrame() { pictureFrame = new JFrame(); // create the JFrame pictureFrame.setResizable(true); // allow the user to resize it pictureFrame.getContentPane().setLayout(new BorderLayout()); // use border layout pictureFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // when close stop pictureFrame.setTitle(picture.getTitle()); PictureExplorerFocusTraversalPolicy newPolicy = new PictureExplorerFocusTraversalPolicy(); pictureFrame.setFocusTraversalPolicy(newPolicy); }
// creates the JFrame, and puts first room onto panel public static void main(String[] s) throws IOException { JFrame f = new JFrame(); f.getContentPane().add(new Adventure()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); Environment Layout = new Environment(); wallLayout = Layout.walls(mapX, mapY); }