public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException { JFrame jf = new JFrame(); AttributesPanel colpal = new AttributesPanel(); colpal.setEntity(new FrameFact("hola")); colpal.setEntity(new FrameFact("hola")); jf.getContentPane().add(colpal); jf.pack(); jf.show(); jf.pack(); }
public static void main(String[] args) { int i = 3; // Default to 3 if (args.length >= 1) { try { i = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.out.println("Usage: 'java SierpinskyTriangle [level]'\nNow setting level to " + i); } } final int level = i; JFrame frame = new JFrame("Sierpinsky Triangle - Java"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override public void paintComponent(Graphics g) { g.setColor(Color.BLACK); drawSierpinskyTriangle(level, 20, 20, 360, (Graphics2D) g); } }; panel.setPreferredSize(new Dimension(400, 400)); frame.add(panel); frame.pack(); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); }
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); }
/** 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); }
private void create() { JFrame f = new JFrame("JSplitPane"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyPanel p1 = new MyPanel(Color.red); MyPanel p2 = new MyPanel(Color.blue); final JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, p1, p2); Timer timer = new Timer( 200, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ratio += delta; if (ratio >= 1.0) { ratio = 1.0; delta = -delta; } else if (ratio <= 0) { delta = -delta; ratio = 0; } jsp.setDividerLocation(ratio); } }); f.add(jsp); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); timer.start(); }
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); }
/** GUIコンポーネントを初期化する。 */ public void initComponent() { frame = new JFrame(ClientContext.getFrameTitle(title)); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { stop(); } }); JPanel contentPane = createBrowsePane(); contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11)); contentPane.setOpaque(true); frame.setContentPane(contentPane); frame.pack(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int n = ClientContext.isMac() ? 3 : 2; int x = (screen.width - frame.getPreferredSize().width) / 2; int y = (screen.height - frame.getPreferredSize().height) / n; frame.setLocation(x, y); blockGlass = new BlockGlass(); frame.setGlassPane(blockGlass); frame.setVisible(true); }
/** * 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); }
private static void badFetch() { final JFrame frame = new JFrame("TestFetchWebGui"); final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel(); final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel"); frame.add(outerPanel); outerPanel.setLayout(new BorderLayout()); buttonPanel.setLayout(new GridLayout(2, 1)); buttonPanel.add(fetchButton); buttonPanel.add(cancelButton); outerPanel.add(buttonPanel, BorderLayout.EAST); final TextArea textArea = new TextArea(25, 80); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); outerPanel.add(textArea, BorderLayout.WEST); fetchButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { for (String url : urls) { System.out.println("Fetching " + url); String page = getPage(url, 200); textArea.append(String.format("%-40s%7d%n", url, page.length())); } } }); frame.pack(); frame.setVisible(true); }
// ------------------------------------------------------------------- public static void main(String[] args) { // Create the window JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(300, 100)); frame.setTitle("A frame"); frame.setLayout(new FlowLayout()); // This will be discuss in the next lesson // Create and add the first button JButton button1 = new JButton(); button1.setText("I'm a button."); button1.setBackground(Color.BLUE); frame.add(button1); // Create and add the second button JButton button2 = new JButton(); button2.setText("Click me!"); button2.setBackground(Color.RED); frame.add(button2); // Reset the sizes of the buttons and window frame.pack(); // Actually put the window on the screen and draw all its components 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 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 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); }
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 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 SchiebePuzzle() { JFrame jF = new JFrame("Misc_2015/SchiebePuzzle"); jF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jF.setLayout(new GridLayout(YY, XX)); // ggf zu ändern try { BufferedImage fuYou = ImageIO.read(new File("fuYou.jpg")); int w = fuYou.getWidth(); int h = fuYou.getHeight(); for (int y = 0; y < YY; y++) for (int x = 0; x < XX; x++) { buttons[y][x] = new PuzzButton( new ImageIcon(fuYou.getSubimage(x * (w / XX), y * (h / YY), w / XX, h / YY))); buttons[y][x].setBorder(new LineBorder(Color.BLACK, 1)); buttons[y][x].setActionCommand("" + x + y); buttons[y][x].setName("" + x + y); buttons[y][x].setPosY(y); buttons[y][x].setPosX(x); buttons[y][x].addActionListener(this); jF.add(buttons[y][x]); } } catch (IOException e) { System.out.println("Bild nicht gefunden!"); } jF.pack(); jF.setVisible(true); }
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(); } }); }
/** The entry main() method */ public static void main(String[] args) { // Create the OpenGL rendering canvas GLCanvas canvas = new GLCanvas(); // heavy-weight GLCanvas canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT)); canvas.addGLEventListener(new JOGL2Nehe11Flag()); // Create a animator that drives canvas' display() at the specified FPS. final FPSAnimator animator = new FPSAnimator(canvas, FPS, true); // Create the top-level container frame final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame frame.getContentPane().add(canvas); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Use a dedicate thread to run the stop() to ensure that the // animator stops before program exits. new Thread() { @Override public void run() { animator.stop(); // stop the animator loop System.exit(0); } }.start(); } }); frame.setTitle(TITLE); frame.pack(); frame.setVisible(true); animator.start(); // start the animation loop }
public static void main(String[] args) { JFrame frame = new JFrame("Add"); frame.setLocation(500, 400); // frame.setPreferredSize(new Dimension(250, 100)); Container contentPane = frame.getContentPane(); FlowLayout layout = new FlowLayout(); contentPane.setLayout(layout); JPanel panel = new JPanel(); panel.add(new JTextField(6)); panel.add(new JLabel("+")); panel.add(new JTextField(6)); panel.add(new JLabel("=")); panel.add(new JTextField(6)); contentPane.add(panel, BorderLayout.CENTER); JPanel panel2 = new JPanel(); panel2.add(new JButton("확인")); panel2.add(new JButton("취소")); contentPane.add(panel2, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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); }
Main() { f = new JFrame("Wiki Seach"); JPanel p = new JPanel(); JPanel p1 = new JPanel(); b = new JButton("Search"); b1 = new JButton("Exit"); t = new JTextField(30); b.addActionListener(this); b1.addActionListener(this); p1.add(b); p1.add(b1); p.add(t); f.setLayout(new GridLayout(2, 1)); f.add(p); f.add(p1); f.pack(); f.setLocationRelativeTo(null); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.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 gameWindow = new JFrame("Tic Tac Toe"); gameWindow.add(new TicTacToeGame()); gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameWindow.pack(); gameWindow.setVisible(true); }
public void show() { FloorcJson floorcJson = null; try { floorcJson = Settings.get(); } catch (Throwable ignored) { } HashMap<String, String> auth = floorcJson != null ? floorcJson.auth.get(Constants.defaultHost) : null; String username = "******"; if (auth != null) { username = auth.get("username"); } usernameInput.setText(username); frame = new JFrame(); frame.getContentPane().add(contentContainer); frame.setMinimumSize(new Dimension(650, 500)); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.pack(); contentContainer.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setVisible(true); String contents = "<html><body><p>When you submit an " + "issue we will be notified right away. If we have contact information for you<br/> we will respond. You can also " + "contact us via [email protected], on IRC in #floobits<br/> " + "on Freenode, or via @floobits Twitter. If you run into " + "a bug it may help us if you send us your <br/>log. You can find it by going to Help -> Find " + "log.... </p></body></html>"; instructionsLabel.setText(contents); instructionsLabel.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); }
public void launchTrajectoryRenderer() { Visualizer tv = this.getTrajectoryRenderLayerBase(); List<EpisodeAnalysis> trajectories = EpisodeAnalysis.parseFilesIntoEAList(this.expertDir, this.domain, this.sp); TrajectoryRenderer tr = new TrajectoryRenderer( trajectories, GridWorldDomain.CLASSAGENT, GridWorldDomain.ATTX, GridWorldDomain.ATTY, new double[] {0, 30, .5}, new double[] {0, 30, .5}, 3.f, 10.f); tv.addRenderLayer(tr); tv.updateState(trajectories.get(0).getState(0)); JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(800, 800)); frame.getContentPane().add(tv); frame.pack(); frame.setVisible(true); }
/** * Tests out the panel from the command line. * * @param args ignored. */ public static void main(String[] args) { try { final JFrame jf = new JFrame("Generator Property Iterator"); jf.getContentPane().setLayout(new BorderLayout()); GeneratorPropertyIteratorPanel gp = new GeneratorPropertyIteratorPanel(); jf.getContentPane().add(gp, BorderLayout.CENTER); jf.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { jf.dispose(); System.exit(0); } }); jf.pack(); jf.setVisible(true); System.err.println("Short nap"); Thread.currentThread().sleep(3000); System.err.println("Done"); gp.setExperiment(new Experiment()); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } }
public static void main(String[] args) { JFrame mainFrame = new JFrame("TestPopupWindow"); mainFrame.getContentPane().add(new TestPopupWindow()); mainFrame.pack(); mainFrame.setLocationRelativeTo(null); mainFrame.setVisible(true); }
public static void main(String[] arg) { // init table with Random Random alea = new Random(System.currentTimeMillis()); for (int i = 0; i < table.length; i++) { table[i] = alea.nextInt(10); } System.out.println(Arrays.toString(table)); // pick median values 3 by 3 using Arrays.sort for (int i = 1; (i < table.length - 1); i++) { int[] sort3 = {table[i - 1], table[i], table[i + 1]}; Arrays.sort(sort3); median[i] = sort3[1]; System.out.printf("%d %d %d : %d\n", table[i - 1], table[i], table[i + 1], median[i]); } System.out.println(Arrays.toString(median)); // create Frame + Panel + Graphics JFrame cadre = new JFrame(); JPanel ardoise = new Graph(); cadre.setVisible(true); cadre.setContentPane(ardoise); cadre.pack(); cadre.setLocation(100, 100); }
public static void main(final String[] args) { JFrame frame = new JFrame("Credit calculator"); frame.setContentPane(new HypothecCalculator().mainPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); 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); }