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); }
public void go() { JFrame frame = new JFrame("JFrame"); JPanel mainPanel = new JPanel(); outgoing = new JTextField(20); JButton sendButton = new JButton("send"); sendButton.addActionListener(new SendButtonListener()); mainPanel.add(outgoing); mainPanel.add(sendButton); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); setUpNetworking(); frame.setSize(400, 500); frame.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.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public void initUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JPopupMenu.setDefaultLightWeightPopupEnabled(false); frame = new JFrame("Project Benelux | 317 | Fullscreen - Resizeable"); frame.setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gamePanel = new JPanel(); new AutoUpdater().run(); webclient = false; gamePanel.setLayout(new BorderLayout()); gamePanel.add(this); JMenu fileMenu = new JMenu("File"); String[] mainButtons = new String[] {"-", "Exit", "-"}; for (String name : mainButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) { fileMenu.addSeparator(); } else { menuItem.addActionListener(this); fileMenu.add(menuItem); } } JMenuBar menuBar = new JMenuBar(); JMenuBar jmenubar = new JMenuBar(); Dimension dimension1 = new Dimension(765 + 16, 503 + 59); frame.setMinimumSize(dimension1); frame.add(jmenubar); menuBar.add(fileMenu); frame.getContentPane().add(menuBar, BorderLayout.NORTH); frame.getContentPane().add(gamePanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); // can see the client frame.setResizable(true); // resizeable frame init(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { String propFileName = null; if (args.length > 0) { propFileName = args[0]; } InterfaceSpeed application = new InterfaceSpeed(propFileName); application.init(); application.start(); JFrame frame = new JFrame(); frame.setTitle(application.getClass().getName()); frame.getContentPane().add(application, BorderLayout.CENTER); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setBounds(50, 50, 400, 100); frame.setVisible(true); }
public void initUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JPopupMenu.setDefaultLightWeightPopupEnabled(false); frame = new JFrame("Vestige-x Developers Client"); frame.setIconImage( Toolkit.getDefaultToolkit().getImage(signlink.findcachedir() + "Cursor.png")); frame.setLayout(new BorderLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel gamePanel = new JPanel(); gamePanel.setLayout(new BorderLayout()); gamePanel.add(this); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int w = 765; int h = 503; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; frame.setLocation(x, y); gamePanel.setPreferredSize(new Dimension(765, 503)); JMenu fileMenu = new JMenu(" File "); JMenu toolMenu = new JMenu(" Tools "); JMenu infoMenu = new JMenu(" Info "); JMenu toggleMenu = new JMenu(" Toggles "); JMenu profileMenu = new JMenu(" Links "); JButton shotMenu = new JButton("Take Screenshot"); shotMenu.setActionCommand("Screenshot"); shotMenu.addActionListener(this); String[] mainButtons = new String[] {"View Images", "Exit"}; String[] toolButtons = new String[] {"World Map"}; String[] infoButtons = new String[] {"Client Information", "Support"}; String[] toggleButtons = new String[] {"Toggle 10x Damage", "Untoggle 10x Damage"}; String[] profileButtons = new String[] {"Donate", "Vote", "-", "Highscores", "Guides", "YouTube", "Forums"}; for (String name : mainButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) { fileMenu.addSeparator(); } else { menuItem.addActionListener(this); fileMenu.add(menuItem); } } for (String name : toolButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) toolMenu.addSeparator(); else { menuItem.addActionListener(this); toolMenu.add(menuItem); } } for (String name : infoButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) infoMenu.addSeparator(); else { menuItem.addActionListener(this); infoMenu.add(menuItem); } } for (String name : toggleButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator(); else { menuItem.addActionListener(this); toggleMenu.add(menuItem); } } for (String name : profileButtons) { JMenuItem menuItem = new JMenuItem(name); if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator(); else { menuItem.addActionListener(this); profileMenu.add(menuItem); } } JMenuBar menuBar = new JMenuBar(); JMenuBar jmenubar = new JMenuBar(); frame.add(jmenubar); menuBar.add(fileMenu); menuBar.add(toolMenu); menuBar.add(infoMenu); // menuBar.add(toggleMenu); menuBar.add(profileMenu); menuBar.add(shotMenu); frame.getContentPane().add(menuBar, BorderLayout.NORTH); frame.getContentPane().add(gamePanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); // can see the client frame.setResizable(false); // resizeable frame init(); } catch (Exception e) { e.printStackTrace(); } }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }