public void init() { // 向内部窗口中添加组件 iframe.add(new JScrollPane(new JTextArea(8, 40))); desktop.setPreferredSize(new Dimension(400, 300)); // 把虚拟桌面添加到JFrame窗口中 jf.add(desktop); // 设置内部窗口的大小、位置 iframe.reshape(0, 0, 300, 200); // 显示并选中内部窗口 iframe.show(); desktop.add(iframe); JPanel jp = new JPanel(); deskBn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 弹出内部对话框,以虚拟桌面作为父组件 JOptionPane.showInternalMessageDialog(desktop, "属于虚拟桌面的对话框"); } }); internalBn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 弹出内部对话框,以内部窗口作为父组件 JOptionPane.showInternalMessageDialog(iframe, "属于内部窗口的对话框"); } }); jp.add(deskBn); jp.add(internalBn); jf.add(jp, BorderLayout.SOUTH); jf.pack(); jf.setVisible(true); }
public MainUI() { super("Neato Burrito"); dLog.trace("In MainUI: " + MainUI.class.getCanonicalName()); this.setBounds(0, 0, 500, 500); Container container = getContentPane(); container.add(theDesktop); setJMenuBar(menubar); JMenu fileMenu = new JMenu("File"); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setMnemonic('X'); exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exitItem); menubar.add(fileMenu); StatusUI statUI = new StatusUI(); statUI.setVisible(true); theDesktop.add(statUI); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); setVisible(true); }
/** This method will create a new frame to place a new Sudoku puzzle. */ protected void createNewGameFrame() { newGameFrame = new SudokuInternal(); newGameFrame.setVisible(true); newGameFrame.setSize(500, 280); newGameFrame.doneButton.addActionListener(new DoneActionListener()); desktop.add(newGameFrame); }
public void openInBox() { JInternalFrame doc = new MetalworksInBox(); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) { } }
public void openHelpWindow() { JInternalFrame help = new MetalworksHelp(); desktop.add(help, HELPLAYER); try { help.setVisible(true); help.setSelected(true); } catch (java.beans.PropertyVetoException e2) { } }
/** This method will create a frame to show the user all the scores in order. */ protected void createHighscoreFrame() { highScoreFrame = new Highscore(); highScoreFrame.setVisible(true); highScoreFrame.setBounds( 250, // left 10, // top 10, // bottom 10); // right highScoreFrame.newGame.addActionListener(new NewGameButtonListener()); highScoreFrame.pack(); desktop.add(highScoreFrame); }
/** This method will create a frame to show the user his or her Sudoku performance. */ protected void createScoreFrame() { // test = new Score(); scoreFrame.discard.addActionListener(new DiscardButtonListener()); scoreFrame.submit.addActionListener(new SubmitHighscoreButtonListener()); scoreFrame.setLayer(JLayeredPane.PALETTE_LAYER); scoreFrame.setVisible(true); scoreFrame.setBounds( 250, // left 10, // top 10, // bottom 10); // right scoreFrame.setSize(300, 400); scoreFrame.setTitle("Score"); scoreFrame.pack(); desktop.add(scoreFrame); }
private void handleSpecialCase(String cname, int condition) { Component comp = null; JComponent mapComp = null; try { if (cname.equals("javax.swing.JApplet") || cname.equals("javax.swing.JDialog") || cname.equals("javax.swing.JFrame") || cname.equals("javax.swing.JWindow")) { comp = (Component) Class.forName(cname).newInstance(); mapComp = (JComponent) ((JApplet) comp).getLayeredPane(); results.setText("Map entries for " + cname + " (delegated to JRootPane):\n\n"); } else if (cname.equals("javax.swing.JInternalFrame")) { JDesktopPane jdp = new JDesktopPane(); JInternalFrame jif = new JInternalFrame("Demo"); jif.setVisible(true); jdp.add(jif); mapComp = jif; } if (inputB.isSelected()) { loadInputMap(mapComp.getInputMap(condition), ""); results.append("\n"); } if (actionB.isSelected()) { loadActionMap(mapComp.getActionMap(), ""); results.append("\n"); } if (bindingB.isSelected()) { loadBindingMap(mapComp, condition); } } catch (ClassCastException cce) { results.setText(cname + " is not a subclass of JComponent."); } catch (ClassNotFoundException cnfe) { results.setText(cname + " was not found."); } catch (InstantiationException ie) { results.setText(cname + " could not be instantiated."); } catch (Exception e) { results.setText("Exception found:\n" + e); e.printStackTrace(); } }
public void selectEntityFrame(DustEntity entity, boolean createIfMissing) { EntityFrame iFrm = mapEntityFrames.get(entity); if (null == iFrm) { if (createIfMissing) { iFrm = new EntityFrame(entity); mapEntityFrames.put(entity, iFrm); desktop.add(iFrm); } } if (null != iFrm) { iFrm.show(); iFrm.toFront(); try { iFrm.setSelected(true); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public MainWindow() { JMenuItem showTextItem, showContentItem, showStatsItem; JMenuItem consoleWinItem, treeWinItem, traceWinItem; // our libgist execution thread opThread = new OpThread(this); Libgist.setBreakHandler(opThread); opThread.start(); cmd = new LibgistCommand(); menuBar = new JMenuBar(); setJMenuBar(menuBar); // create toolbar and console window with text area getContentPane().removeAll(); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // desktop pane + console frame desktop = new JDesktopPane(); desktop.setOpaque(true); desktop.setBackground(Color.lightGray); consoleFrame = new ConsoleWindow(200, desktop); desktop.add(consoleFrame, JLayeredPane.PALETTE_LAYER); // debugging actions for toolbar: // notify opThread of what to do when it hits a breakpoint stepAction = new AbstractAction("Step") { public void actionPerformed(ActionEvent e) { opThread.step(); } }; cancelAction = new AbstractAction("Cancel") { public void actionPerformed(ActionEvent e) { scriptWasCancelled = true; // don't call it after next line! opThread.cancel(); } }; nextAction = new AbstractAction("Next") { public void actionPerformed(ActionEvent e) { opThread.next(); } }; contAction = new AbstractAction("Continue") { public void actionPerformed(ActionEvent e) { opThread.cont(); } }; // opThread is currently executing a script and we want it to stop: // tell libgist directly to suspend execution once opThread is done // with the current operation stopAction = new AbstractAction("Stop") { public void actionPerformed(ActionEvent e) { Libgist.singleStep(); } }; // toolbar JToolBar toolbar = new JToolBar(); toolbar.add(stepAction).setText("Step"); toolbar.add(nextAction).setText("Next"); toolbar.add(contAction).setText("Continue"); toolbar.add(stopAction).setText("Stop"); toolbar.add(cancelAction).setText("Cancel"); panel.add(toolbar, BorderLayout.NORTH); panel.add(desktop, BorderLayout.CENTER); getContentPane().add(panel); createFileMenu(); createOpsMenu(); createDebugMenu(); createTreeStatsMenu(); createAnalysisMenu(); createWindowsMenu(); setGuiState(INITSTATE); // nothing opened yet // addWindowListener(this); // So we do the right thing on window closing. }
public void updateGuiState(int priorState, LibgistCommand cmd, boolean success) { switch (cmd.cmdType) { case LibgistCommand.CREATE: case LibgistCommand.OPEN: resetState(); if (!success) return; // done setGuiState(IDXOPENSTATE); isOpen = true; idxName = cmd.indexName.toString(); if (cmd.cmdType == LibgistCommand.CREATE) { resetConfig(); } else { restoreConfig(); } // setTitle("amdb: " + filename); setTree(idxName); try { treeView = new TreeView(desktop); // creates a display of the opened index desktop.add(treeView, JLayeredPane.PALETTE_LAYER); } catch (LibgistException e) { // what to do now? consoleFrame.echoInfo("new TreeView() failed"); } break; case LibgistCommand.CLOSE: saveConfig(); resetState(); break; case LibgistCommand.OPENANL: resetState(); if (!success) return; // done // enable menu items and open tree view setGuiState(ANLOPENSTATE); // setTitle("amdb: " + filename); setTree(idxName); try { treeView = new TreeView(desktop); // creates a display of the opened index desktop.add(treeView, JLayeredPane.PALETTE_LAYER); } catch (LibgistException e) { // what to do now? consoleFrame.echoInfo("new TreeView() failed"); } // get ready to display dialogs if (analysisInfo.actualHasWkldStats) { wkldStatsDlg.init(treeView); } if (analysisInfo.actualHasSplitStats) { splitStatsDlg.init(treeView); } if (analysisInfo.actualHasPenaltyStats) { penaltyStatsDlg.init(treeView); } break; case LibgistCommand.CLOSEANL: treeView.dispose(); treeView = null; setGuiState(INITSTATE); setTree(""); break; // if these didn't work, we don't care case LibgistCommand.INSERT: case LibgistCommand.REMOVE: case LibgistCommand.FETCH: case LibgistCommand.FLUSH: case LibgistCommand.CREATEANL: case LibgistCommand.SCRIPT: setGuiState(priorState); break; } }
public SceneLayoutApp() { super(); new Pair(); final JFrame frame = new JFrame("Scene Layout"); final JPanel panel = new JPanel(new BorderLayout()); frame.setContentPane(panel); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setMaximumSize(screenSize); frame.setSize(screenSize); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JMenuBar mb = new JMenuBar(); frame.setJMenuBar(mb); final JMenu jMenu = new JMenu("File"); mb.add(jMenu); mb.add(new JMenu("Edit")); mb.add(new JMenu("Help")); JMenu menu = new JMenu("Look and Feel"); // // Get all the available look and feel that we are going to use for // creating the JMenuItem and assign the action listener to handle // the selection of menu item to change the look and feel. // UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lookAndFeelInfos.length; i++) { final UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i]; JMenuItem item = new JMenuItem(lookAndFeelInfo.getName()); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { // // Set the look and feel for the frame and update the UI // to use a new selected look and feel. // UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); SwingUtilities.updateComponentTreeUI(frame); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } } }); menu.add(item); } mb.add(menu); jMenu.add(new JMenuItem(new scene.action.QuitAction())); panel.add(new JScrollPane(desktopPane), BorderLayout.CENTER); final JToolBar bar = new JToolBar(); panel.add(bar, BorderLayout.NORTH); final JComboBox comboNewWindow = new JComboBox( new String[] {"320:180", "320:240", "640:360", "640:480", "1280:720", "1920:1080"}); comboNewWindow.addActionListener(new CreateSceneWindowAction()); comboNewWindow.setBorder(BorderFactory.createTitledBorder("Create New Window")); bar.add(comboNewWindow); bar.add( new AbstractAction("Progress Bars") { /** Invoked when an action occurs. */ @Override public void actionPerformed(ActionEvent e) { new ProgressBarAnimator(); } }); bar.add( new AbstractAction("Sliders") { /** Invoked when an action occurs. */ @Override public void actionPerformed(ActionEvent e) { new SliderBarAnimator(); } }); final JCheckBox permaViz = new JCheckBox(); permaViz.setText("Show the dump window"); permaViz.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); dumpWindow = new JInternalFrame("perma dump window"); dumpWindow.setContentPane(new JScrollPane(permText)); permaViz.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dumpWindow.setVisible(permaViz.isSelected()); } }); comboNewWindow.setMaximumSize(comboNewWindow.getPreferredSize()); permaViz.setSelected(false); bar.add(new CreateWebViewV1Action()); bar.add(new CreateWebViewV2Action()); bar.add(permaViz); desktopPane.add(dumpWindow); dumpWindow.setSize(400, 400); dumpWindow.setResizable(true); dumpWindow.setClosable(false); dumpWindow.setIconifiable(false); final JMenuBar m = new JMenuBar(); final JMenu cmenu = new JMenu("Create"); m.add(cmenu); final JMenuItem menuItem = new JMenuItem( new AbstractAction("new") { @Override public void actionPerformed(ActionEvent e) { Runnable runnable = new Runnable() { public void run() { Object[] in = (Object[]) XSTREAM.fromXML(permText.getText()); final JInternalFrame ff = new JInternalFrame(); final ScenePanel c = new ScenePanel(); ff.setContentPane(c); desktopPane.add(ff); final Dimension d = (Dimension) in[0]; c.setMaximumSize(d); c.setPreferredSize(d); ff.setSize(d.width + 50, d.height + 50); ScenePanel.panes.put(c, (List<Pair<Point, ArrayList<URL>>>) in[1]); c.invalidate(); c.repaint(); ff.pack(); ff.setClosable(true); ff.setMaximizable(false); ff.setIconifiable(false); ff.setResizable(false); ff.show(); } }; SwingUtilities.invokeLater(runnable); } }); cmenu.add(menuItem); // JMenuBar menuBar = new JMenuBar(); // getContentPane().add(menuBar); dumpWindow.setJMenuBar(m); frame.setVisible(true); }
/** * Method to handle hyper link events. * * @param event hyper link event */ public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { setCursor(cbusy); try { URL url = event.getURL(); int ind1 = event.getDescription().indexOf("["); int ind2 = event.getDescription().lastIndexOf("]"); String search = ""; if (ind1 > -1 && ind2 > -1) search = event.getDescription().substring(ind1 + 1, ind2); else { ind1 = event.getDescription().indexOf("=") + 1; // genedb if (ind1 > -1) search = event.getDescription().substring(ind1); } if (desktop != null) { if (BigPane.srsTabPane.isSelected()) setUpSRSFrame(url, search); if (BigPane.srsWin.isSelected()) { int hgt = (2 * desktop.getHeight()) / 3; Annotation edPane = new Annotation(url); JScrollPane jsp = new JScrollPane(edPane); JInternalFrame jif = new JInternalFrame( "SRS " + search, true, // resizable true, // closable true, // maximizable true); // iconifiable); JMenuBar menuBar = new JMenuBar(); menuBar.add(new CommonMenu(jif)); jif.setJMenuBar(menuBar); jif.getContentPane().add(jsp); jif.setLocation(0, 0); jif.setSize(800, hgt); jif.setVisible(true); desktop.add(jif); } if (BigPane.srsBrowser.isSelected()) BrowserControl.displayURL(event.getDescription()); } else { setPage(url); back.add(url); } } catch (IOException ioe) { String msg = event.getDescription(); if (msg.length() > 50) msg = msg.substring(0, 50) + "...."; JOptionPane.showMessageDialog( this, "Cannot reach URL:\n" + msg, "Cannot Connect", JOptionPane.INFORMATION_MESSAGE); // ioe.printStackTrace(); // ("Can't follow link to " + // event.getURL().toExternalForm() ); } setCursor(cdone); } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) { try { JTextField statusField = (JTextField) BigPane.srsFrame.getContentPane().getComponent(1); statusField.setText(event.getDescription()); } catch (Exception exp) { } } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) { try { JTextField statusField = (JTextField) BigPane.srsFrame.getContentPane().getComponent(1); statusField.setText(""); } catch (Exception exp) { } } }
/** The graphic handling and deployment. */ private void initComponents() { jDesktopPane1 = new javax.swing.JDesktopPane(); jInternalFrame1 = new javax.swing.JInternalFrame(); tf = new javax.swing.JTextField(); b1 = new javax.swing.JButton(); jInternalFrame3 = new javax.swing.JInternalFrame(); ta = new javax.swing.JTextArea(); jsp_ta = new javax.swing.JScrollPane(ta); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem3 = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JSeparator(); jMenuItem4 = new javax.swing.JMenuItem(); jInternalFrame1 .getContentPane() .setLayout( new javax.swing.BoxLayout( jInternalFrame1.getContentPane(), javax.swing.BoxLayout.X_AXIS)); jInternalFrame1.setIconifiable(true); jInternalFrame1.setMaximizable(true); jInternalFrame1.setResizable(true); jInternalFrame1.setTitle("Message editor"); jInternalFrame1.setToolTipText( "Move and resize all of these to make the chat room appearance match your preferences."); jInternalFrame1.setVisible(true); tf.setFont(new java.awt.Font("Lucida Sans", 0, 12)); jInternalFrame1.getContentPane().add(tf); b1.setText("Send Message"); jInternalFrame1.getContentPane().add(b1); jInternalFrame1.setBounds(10, 10, 440, 60); jDesktopPane1.add(jInternalFrame1, javax.swing.JLayeredPane.DEFAULT_LAYER); jInternalFrame3.setIconifiable(true); jInternalFrame3.setMaximizable(true); jInternalFrame3.setResizable(true); jInternalFrame3.setTitle("Messages"); jInternalFrame3.setToolTipText( "Move and resize all of these to make the chat room appearance match your preferences."); jInternalFrame3.setVisible(true); ta.setBackground(new Color(255, 255, 255)); ta.setEditable(false); ta.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // jsp_ta.setAutoscrolls(true); jsp_ta.setDoubleBuffered(true); jInternalFrame3.getContentPane().add(jsp_ta, java.awt.BorderLayout.CENTER); jInternalFrame3.setBounds(10, 80, 420, 240); jDesktopPane1.add(jInternalFrame3, javax.swing.JLayeredPane.DEFAULT_LAYER); getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER); jMenu1.setText("Private room options"); jMenu1.setMnemonic(KeyEvent.VK_O); jMenu1.setToolTipText("Choose some options."); jMenuItem3.setText("Save conversation"); jMenuItem3.setMnemonic(KeyEvent.VK_S); jMenuItem3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); jMenu1.add(jMenuItem3); jMenu1.add(jSeparator1); jMenuItem4.setText("Exit"); jMenuItem4.setMnemonic(KeyEvent.VK_E); jMenuItem4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK)); jMenu1.add(jMenuItem4); jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); this.pack(); b1.addActionListener(this); tf.addActionListener(this); jMenuItem3.addActionListener(this); jMenuItem4.addActionListener(this); posx = (int) Math.random() * 640; posy = (int) Math.random() * 480; this.pack(); this.setSize(dimx, dimy); this.setLocation(posx, posy); this.show(); }