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); }
/** * 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 void create() { JFrame frame = new JFrame(); frame.getContentPane().add(new JScrollPane(jgraph)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
public void openCaptureWindow() { if (framenr - lastcapture_framenr < number_of_frames_before_cwopen) { return; } // Capture Window cw.setVisible(true); cw.toFront(); // Timer for closing the capturewindow TimerTask task = new TimerTask() { @Override public void run() { EventQueue.invokeLater( new Runnable() { public void run() { System.out.println("Closing cw..."); cw.setVisible(false); cwText.setText(""); // Empty text in case there is a text } }); } }; cwTimer = new Timer(); cwTimer.schedule(task, number_of_second_capturewindow * 1000); }
private void _displayRespStrInFrame() { final JFrame frame = new JFrame("Google Static Map - Error"); GUIUtils.setAppIcon(frame, "69.png"); // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); JTextArea response = new JTextArea(_respStr, 25, 80); response.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { /*frame.dispose();*/ } public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }); frame.setContentPane(new JScrollPane(response)); frame.pack(); GUIUtils.centerOnScreen(frame); frame.setVisible(true); }
public void setUpGui() { m1 = new MyDrawPanel(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(m1); f.setBounds(30, 30, 300, 300); f.setVisible(true); } // quit meth
public void mustMakeChoice() { final JFrame frame = new JFrame("Must specify one option"); JPanel panel = new JPanel(); JLabel exitLabel = new JLabel("Must specify one option"); JButton okButton = new JButton("Continue"); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }); panel.setBorder( BorderFactory.createEmptyBorder( 30, // top 30, // left 10, // bottom 30) // right ); panel.setLayout(new GridLayout(0, 1)); panel.add(exitLabel); panel.add(okButton); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { ArrayList<Pattern> patterns = new ArrayList<Pattern>(); ArrayList<Cut> cuts; ArrayList<Garment> garments; patterns.add(new Pattern(2, 2, 1, "Tie")); patterns.add(new Pattern(2, 6, 4, "Skirt")); patterns.add(new Pattern(4, 2, 3, "Blouse")); patterns.add(new Pattern(5, 3, 5, "Dress")); int width = 30; int height = 15; ClothCutter cutter = new ClothCutter(width, height, patterns); System.out.println("Optimized value: " + cutter.optimize()); cuts = cutter.getCuts(); garments = cutter.getGarments(); ClothPanel panel = new ClothPanel(width, height); JFrame frame = new JFrame("A luxurious bolt of fabric"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); sleep(1000); for (int i = 0; i < cuts.size(); i++) { panel.drawCut(cuts.get(i)); sleep(100); } for (int i = 0; i < garments.size(); i++) { System.out.println(garments.get(i)); panel.drawGarment(garments.get(i)); sleep(100); } }
/** Simple test program. */ public static void main(String[] args) { final JFrame frame = new JFrame("Testing AddPersonDialog"); JButton button = new JButton("Click me"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FamilyTree tree = new FamilyTree(); AddPersonDialog dialog = new AddPersonDialog(frame, tree); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); Person newPerson = dialog.getPerson(); if (newPerson != null) { tree.addPerson(newPerson); PrettyPrinter pretty = new PrettyPrinter(new PrintWriter(System.out, true)); pretty.dump(tree); } } }); frame.getContentPane().add(button); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(1); } }); frame.pack(); frame.setVisible(true); }
/** * 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); }
// 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); }
// 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); }
/** * Overrides java.awt.Container.setVisible() so that we are sure that the Frame's size is set * before displaying. */ public void setVisible(boolean state) { if (state) { Dimension bounds = getToolkit().getScreenSize(); setLocation((bounds.width - getSize().width) / 2, (bounds.height - getSize().height) / 2); } super.setVisible(state); }
public void Window() { JFrame f = new JFrame("test"); f.setSize(570, 383); f.add(new test()); f.setLocationRelativeTo(null); f.setResizable(false); f.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 static void main(String[] args) { Chart shc = new Chart("C:/TEMP/table.csv"); JFrame frame = new JFrame("Stock History Chart for " + shc.getSymbol()); frame.getContentPane().add(shc, BorderLayout.CENTER); frame.setSize(640, 480); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
// 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); }
/** * This method creates a JFrame where everything will be displayed INPUT (parameters): none OUTOUT * (return): none */ public static void createAndShowGUI() { JFrame frame = new JFrame("Black Jack"); // title of the JFrame BlackJack demo = new BlackJack(); // create and set up the content pane frame.setContentPane(demo.createContentPane()); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); // what happens if the user presses the x button frame.setSize(950, 760); frame.setVisible(true); // ensure frame is visible }
/* Create and show the graphical user interface. */ private static void createAndShowGUI() { JFrame frame = new JFrame("My Collapsing Puzzle"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Game game = new Game(); frame.setJMenuBar(game.createMenuBar()); frame.setContentPane(game.createContentPane()); frame.setSize(game.getGameSize()); frame.setVisible(true); }
public ArcViewer() { JFrame frame = new JFrame("ArcViewer v.0.9"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add("Center", this); frame.setSize(900, 600); frame.setVisible(true); init(); }
/** Leave Group and close JWhiteBoard */ public void stop() { if (!noChannel) { try { channel.close(); } catch (Exception ex) { System.err.println(ex); } } mainFrame.setVisible(false); mainFrame.dispose(); }
public void actionPerformed(ActionEvent e) { if (!datapanel.isInitialized()) { return; } datapanel.refreshData(); panel.setDisplayPlot(true); panel.update(panel.getGraphics()); frame.setSize(700, 600); frame.setVisible(true); frame.pack(); }
// init private static void init() { if (frame != null) frame.setVisible(false); frame = new JFrame(); offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); offscreen = offscreenImage.createGraphics(); onscreen = onscreenImage.createGraphics(); setXscale(); setYscale(); offscreen.setColor(DEFAULT_CLEAR_COLOR); offscreen.fillRect(0, 0, width, height); setPenColor(); setPenRadius(); setFont(); clear(); // add anti-aliasing RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); offscreen.addRenderingHints(hints); // frame stuff ImageIcon icon = new ImageIcon(onscreenImage); JLabel draw = new JLabel(icon); draw.addMouseListener(std); draw.addMouseMotionListener(std); frame.setContentPane(draw); frame.addKeyListener(std); // JLabel cannot get keyboard focus frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // closes only current window frame.setTitle("Standard Draw"); frame.setJMenuBar(createMenuBar()); frame.pack(); frame.requestFocusInWindow(); frame.setVisible(true); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the event * dispatch thread. */ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("Viettel Enterprise Platform - Module Friendlizer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add content to the window. frame.add(new GuiFriendlizerApp()); // Display the window. frame.pack(); frame.setVisible(true); }
private void initialize() { frame = new JFrame(); frame.setSize(600, 700); // frame.getContentPane().setLayout(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setResizable(false); frame.setTitle("PDF"); // frame.setLocationRelativeTo(null); frame.setVisible(true); // frame.pack(); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the event * dispatch thread. */ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("FileChooserDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add content to the window. frame.add(new FileChooserDemo()); // Display the window. frame.pack(); frame.setVisible(true); }
private void showIDE(boolean show) { SikuliIDE.getInstance().setVisible(show); if (show) { addMinComponentsToPane(mainPane); } else { addMinComponentsToPane(minPane); Container con = minFrame.getContentPane(); con.add(minPane); minFrame.doLayout(); } minFrame.setVisible(!show); }
/** This method sets up the window and displays it. */ private void setupFrame() { JFrame window = new JFrame("Dungeon of Dooom"); window.setIconImage(Toolkit.getDefaultToolkit().getImage("graphics/icon.png")); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); populateFrame(window.getContentPane()); window.pack(); window.setLocationByPlatform(true); window.setVisible(true); Dimension windowSize = new Dimension(608, 606); window.setSize(windowSize); window.setResizable(false); }
public void go() { frame = new JFrame("Quiz Card Player"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); display = new JTextArea(10, 20); display.setFont(bigFont); display.setLineWrap(true); display.setEditable(false); JScrollPane qScroller = new JScrollPane(display); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); nextButton = new JButton("Show Questions"); nextButton.addActionListener(new NextCardListener()); mainPanel.add(qScroller); mainPanel.add(nextButton); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem loadMenuItem = new JMenuItem("Load Card Set"); loadMenuItem.addActionListener(new OpenMenuListener()); fileMenu.add(loadMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(640, 500); frame.setVisible(true); }
public void go() { // build gui frame = new JFrame("Quiz Card Buider"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); question = new JTextArea(6, 20); question.setLineWrap(true); question.setWrapStyleWord(true); question.setFont(bigFont); JScrollPane qScroller = new JScrollPane(question); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); answer = new JTextArea(6, 20); answer.setLineWrap(true); answer.setWrapStyleWord(true); answer.setFont(bigFont); JScrollPane aScroller = new JScrollPane(question); aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JButton nextButton = new JButton("Next Card"); cardList = new ArrayList<QuizCard>(); JLabel qLabel = new JLabel("Question"); JLabel aLabel = new JLabel("Answer"); mainPanel.add(qLabel); mainPanel.add(qScroller); mainPanel.add(aLabel); mainPanel.add(aScroller); mainPanel.add(nextButton); nextButton.addActionListener(new NextCardListener()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem newMenuItem = new JMenuItem("New"); JMenuItem saveMenuItem = new JMenuItem("Save"); newMenuItem.addActionListener(new NewMenuListener()); saveMenuItem.addActionListener(new SaveMenuListener()); fileMenu.add(newMenuItem); fileMenu.add(saveMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(500, 600); frame.setVisible(true); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }