/** *********************************************************************** */ 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 }
public void init() { // a grid to layout the screen nicely JLabel title = new JLabel("THE GAME OF NIM!"); title.setFont(new Font("Times New Roman", Font.PLAIN, 48)); Panel p = new Panel(); resize(500, 100); // declare a new array of buttons a = new JButton[row]; // initialize each of the buttons in the array // with an empty label for (int nNum = 0; nNum < row; nNum++) { a[nNum] = new JButton("8"); p.add(a[nNum]); // each button will have an action listener a[nNum].addActionListener(this); a[nNum].setBackground(Color.yellow); // each button will send a message with its number a[nNum].setActionCommand("" + nNum); } name = JOptionPane.showInputDialog("Enter name Player 1: "); name2 = JOptionPane.showInputDialog("Enter name Player 2: "); JButton reset = new JButton("Reset"); reset.addActionListener(this); reset.setActionCommand("re"); status = new JLabel("Welcome! The player to remove the final stones is the loser!"); add(title); add(status); add(p); add(reset); }
public CollageList() { super(); actionComponent = new Button(); Panel toolBar; setLayout(new BorderLayout()); // ggHScroll = new Scrollbar( Scrollbar.HORIZONTAL, 0, 0x8000, 0, 0x8000 ); ggVScroll = new Scrollbar(Scrollbar.VERTICAL, 0, 0x8000, 0, 0x8000); // ggHScroll.addAdjustmentListener( ggCurve ); ggVScroll.addAdjustmentListener(this); toolBar = new Panel(); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2)); ggAdd = new JButton(" Add "); ggDel = new JButton(" Delete "); ggDup = new JButton(" Duplicate "); ggAdd.addActionListener(this); ggDel.addActionListener(this); ggDup.addActionListener(this); toolBar.add(ggAdd); toolBar.add(ggDel); toolBar.add(ggDup); add(toolBar, BorderLayout.NORTH); // add( ggHScroll, BorderLayout.SOUTH ); add(ggVScroll, BorderLayout.EAST); add(new CollageCanvas(this), BorderLayout.CENTER); // add( ggCurve, BorderLayout.CENTER ); }
/** * Constructor called from getInstance() * * @param model - A model is needed so that we can observe it and respond to its changes */ private CelsiusView(TemperatureModel model) { // Set up fields this.model = model; this.upButton = new JButton("Raise"); this.downButton = new JButton("Lower"); // Add an observer to the model model.addObserver(this); // Allows us to close the window this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Make the text to display // Edit this for CelsiusView temp = new JLabel("Model Temperature in Celcius: " + model.getC(), SwingConstants.CENTER); this.add(temp); // Make the buttons Panel buttons = new Panel(); buttons.add(upButton); buttons.add(downButton); this.add("South", buttons); this.setSize(400, 100); setLocationRelativeTo(null); }
public void buildChooser() { Panel panel = new Panel(); panel.setLayout(new GridLayout()); for (int i = 1; i <= 3; i++) { for (int x = 1; x <= 2; x++) { panel.add(addButton(i * x + "", Color.yellow)); } } add(panel); }
@Override public void addValue(String inVal) { System.out.println("Selected: " + cb.getSelectedIndex()); switch (cb.getSelectedIndex()) { case 1: cardPH.setValue(inVal); break; case 2: cardCO2.setValue(inVal); break; case 3: cardSOIL.setValue(inVal); break; } }
public ButtonPanel() { int buttonPanelOrient = FlowLayout.CENTER; setLayout(new BorderLayout(0, 5)); buttonPanelOrient = FlowLayout.CENTER; buttonPanel.setLayout(new FlowLayout(buttonPanelOrient)); add(separator, "North"); add(buttonPanel, "Center"); }
public void setBotones() { nombres[0] = JOptionPane.showInputDialog("Nombre del primer jugador 1"); logger.info("nombre del jugador es " + nombres[0]); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { botones[i][j] = new JButton(" "); panel.add(botones[i][j]); botones[i][j].addActionListener(this); } } reiniciar.addActionListener(this); panelPrincipal.add(panel, BorderLayout.CENTER); panelPrincipal.add(reiniciar, BorderLayout.SOUTH); this.add(panelPrincipal); setSize(500, 500); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
// Color gre; Rules(String se) { email = se; conti = new Button("Continue"); rules = new Button("ClicK Here For Rules"); p1 = new JOptionPane(); Icon image = new ImageIcon("books.jpg"); Icon image1 = new ImageIcon("girl.jpg"); Icon image2 = new ImageIcon("uit.jpg"); gl = new GridBagLayout(); gbc = new GridBagConstraints(); conti.addActionListener(this); rules.addActionListener(this); // gre=new Color(117,102,185); p = new Panel(); p2 = new Panel(); p3 = new Panel(); p4 = new Panel(); f = new Frame(); pic = new JLabel(image); pic1 = new JLabel(image1); pic2 = new JLabel(image2); gbc.anchor = GridBagConstraints.SOUTHWEST; gl.setConstraints(pic1, gbc); gbc.anchor = GridBagConstraints.SOUTHEAST; gl.setConstraints(pic, gbc); Insets is = new Insets(30, 30, 30, 30); gbc.insets = is; gbc.ipadx = 14; gbc.ipady = 8; gl.setConstraints(rules, gbc); gl.setConstraints(conti, gbc); p2.setLayout(gl); p4.add(pic2); p2.add(pic); p3.setLayout(gl); p3.add(pic1); p.add(conti); p.add(rules); p.setLayout(gl); f.add(p4, "North"); f.add(p3, "East"); f.add(p2, "West"); f.add(p, "Center"); f.setTitle("RULES BOOK"); // f.setBackground(gre); f.setVisible(true); f.setSize(900, 600); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); }
public void init() { Panel p = new Panel(); p.add(btCopy); p.add(btPaste); btCopy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 将一个多行文本域里的字符串封装成StringSelection对象 StringSelection contents = new StringSelection(jtaCopyTo.getText()); // 将StringSelection对象放入剪贴板 clipboard.setContents(contents, null); } }); btPaste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 如果剪贴板中包含stringFlavor内容 if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) { try { // 取出剪贴板中stringFlavor内容 String content = (String) clipboard.getData(DataFlavor.stringFlavor); jtaPaste.append(content); } catch (Exception e) { e.printStackTrace(); } } } }); // 创建一个水平排列的Box容器 Box box = new Box(BoxLayout.X_AXIS); // 将两个多行文本域放在Box容器中 box.add(jtaCopyTo); box.add(jtaPaste); // 将按钮所在Panel、Box容器添加到Frame窗口中 f.add(p, BorderLayout.SOUTH); f.add(box, BorderLayout.CENTER); f.pack(); f.setVisible(true); }
Board() { addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(screenSize); setLocation(0, 0); r3 = Math.sqrt(3); Button ng, eg, ab; ng = new Button("New Game"); eg = new Button("Exit Game"); ab = new Button("About"); gold = new ImageIcon("./coin2.jpg").getImage(); silver = new ImageIcon("./coin1.jpg").getImage(); Panel pan = new Panel(); pan.setLayout(new FlowLayout()); pan.add(ng); pan.add(eg); pan.add(ab); setLayout(new BorderLayout()); add(pan, BorderLayout.NORTH); newGame(); ng.addActionListener(this); eg.addActionListener(this); ab.addActionListener(this); addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { int mx = e.getX(), my = e.getY(); place(mx, my); } }); }
public void add(Button button) { buttonPanel.add(button); }
// initialize client UI private void initComponents() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle("Distributed Hash Table Client"); keyBox = new JTextField(7); valueBox = new JTextField(15); serverBox = new JTextField(2); keyLabel = new JLabel("Key: "); keyLabel.setLabelFor(keyBox); valueLabel = new JLabel("Value: "); valueLabel.setLabelFor(valueBox); serverLabel = new JLabel("Server Id: "); serverLabel.setLabelFor(serverBox); serverOutput = new JLabel("Server Output:"); JPanel pane = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; pane.add(keyLabel, c); c.gridx = 1; pane.add(keyBox, c); c.gridx = 0; c.gridy = 1; pane.add(valueLabel, c); c.gridx = 1; pane.add(valueBox, c); c.gridx = 0; c.gridy = 2; pane.add(serverLabel, c); c.gridx = 1; pane.add(serverBox, c); RadioListener radioListener = new RadioListener(); actionGroup = new ButtonGroup(); insertRadionButton = new JRadioButton("Insert"); insertRadionButton.setSelected(true); insertRadionButton.setActionCommand("insert"); insertRadionButton.addActionListener(radioListener); lookupRadionButton = new JRadioButton("Lookup"); lookupRadionButton.setActionCommand("lookup"); lookupRadionButton.addActionListener(radioListener); deleteRadionButton = new JRadioButton("Delete"); deleteRadionButton.setActionCommand("delete"); deleteRadionButton.addActionListener(radioListener); countRadionButton = new JRadioButton("Count"); countRadionButton.setActionCommand("count"); countRadionButton.addActionListener(radioListener); actionGroup.add(insertRadionButton); actionGroup.add(lookupRadionButton); actionGroup.add(deleteRadionButton); actionGroup.add(countRadionButton); c.gridx = 2; c.gridy = 0; pane.add(insertRadionButton, c); c.gridy = 1; pane.add(lookupRadionButton, c); c.gridy = 2; pane.add(deleteRadionButton, c); c.gridy = 3; pane.add(countRadionButton, c); execButton = new JButton("Execute"); execButton.addActionListener(new ExecButtonListener()); c.gridx = 3; c.gridy = 0; pane.add(execButton, c); purgeButton = new JButton("Purge"); purgeButton.addActionListener(new PurgeButtonListener()); c.gridx = 3; c.gridy = 2; pane.add(purgeButton, c); resultArea = new JTextArea(28, 70); resultArea.setEditable(false); scrollingArea = new JScrollPane(resultArea); upperPanel = new Panel(new BorderLayout()); upperPanel.add(pane, BorderLayout.CENTER); resultPanel = new Panel(); resultPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); resultPanel.add(serverOutput); resultPanel.add(scrollingArea); add(upperPanel, BorderLayout.NORTH); add(resultPanel, BorderLayout.CENTER); setSize(800, 600); this.setVisible(true); }
public Button add(String buttonLabel) { Button addMe = new Button(buttonLabel); buttonPanel.add(addMe); return addMe; }
paintboard1(String s) { super(s); addMouseMotionListener(this); addMouseListener(this); paintInfo = new Vector(); /* 各工具按钮及选择项 */ // 颜色选择 ColChoice = new Choice(); ColChoice.add("black"); ColChoice.add("red"); ColChoice.add("blue"); ColChoice.add("green"); ColChoice.addItemListener(this); // 画笔大小选择 SizeChoice = new Choice(); SizeChoice.add("1"); SizeChoice.add("3"); SizeChoice.add("5"); SizeChoice.add("7"); SizeChoice.add("9"); SizeChoice.addItemListener(this); // 橡皮大小选择 EraserChoice = new Choice(); EraserChoice.add("5"); EraserChoice.add("9"); EraserChoice.add("13"); EraserChoice.add("17"); EraserChoice.addItemListener(this); // ////////////////////////////////////////////////// toolPanel = new Panel(); clear = new Button("清除"); eraser = new Button("橡皮"); pen = new Button("画笔"); drLine = new Button("画直线"); drCircle = new Button("画圆形"); drRect = new Button("画矩形"); openPic = new Button("打开图画"); savePic = new Button("保存图画"); colchooser = new Button("显示调色板"); // 各组件事件监听 clear.addActionListener(this); eraser.addActionListener(this); pen.addActionListener(this); drLine.addActionListener(this); drCircle.addActionListener(this); drRect.addActionListener(this); openPic.addActionListener(this); savePic.addActionListener(this); colchooser.addActionListener(this); 颜色 = new Label("画笔颜色", Label.CENTER); 大小B = new Label("画笔大小", Label.CENTER); 大小E = new Label("橡皮大小", Label.CENTER); // 面板添加组件 toolPanel.add(openPic); toolPanel.add(savePic); toolPanel.add(pen); toolPanel.add(drLine); toolPanel.add(drCircle); toolPanel.add(drRect); toolPanel.add(颜色); toolPanel.add(ColChoice); toolPanel.add(大小B); toolPanel.add(SizeChoice); toolPanel.add(colchooser); toolPanel.add(eraser); toolPanel.add(大小E); toolPanel.add(EraserChoice); toolPanel.add(clear); // 工具面板到APPLET面板 add(toolPanel, BorderLayout.NORTH); setBounds(230, 50, 900, 650); setVisible(true); validate(); // dialog for save and load openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD); openPicture.setVisible(false); savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE); savePicture.setVisible(false); openPicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { openPicture.setVisible(false); } }); savePicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { savePicture.setVisible(false); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
void launch() { f.setSize(800, 800); p.setLayout(null); l1.setBounds(600, 10, 150, 36); l2.setBounds(100, 30, 400, 70); l13.setBounds(2, 90, 1200, 20); l14.setBounds(80, 150, 250, 30); t1.setBounds(330, 150, 150, 30); b1.setBounds(500, 150, 100, 30); l15.setBounds(2, 200, 1200, 20); b6.setBounds(600, 50, 100, 30); l3.setBounds(100, 250, 100, 30); t2.setBounds(300, 250, 150, 30); l4.setBounds(100, 300, 150, 30); t3.setBounds(300, 300, 150, 30); l5.setBounds(100, 350, 150, 30); t4.setBounds(300, 350, 150, 30); l6.setBounds(100, 400, 100, 30); t5.setBounds(300, 400, 150, 30); l7.setBounds(100, 450, 100, 30); c1.setBounds(300, 450, 60, 30); c2.setBounds(400, 450, 60, 30); l8.setBounds(100, 500, 100, 30); t6.setBounds(300, 500, 150, 30); l9.setBounds(100, 550, 100, 30); t7.setBounds(300, 550, 150, 30); l10.setBounds(100, 600, 120, 30); t8.setBounds(300, 600, 150, 30); l11.setBounds(100, 650, 100, 30); t9.setBounds(300, 650, 150, 30); l12.setBounds(100, 700, 150, 30); t10.setBounds(300, 700, 150, 30); b2.setBounds(500, 400, 100, 30); b3.setBounds(500, 500, 100, 30); b4.setBounds(500, 600, 100, 30); b5.setBounds(650, 150, 100, 30); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); c1.addItemListener(this); c2.addItemListener(this); p.add(l1); p.add(l2); p.add(l13); p.add(l14); p.add(t1); p.add(b1); p.add(l15); p.add(b5); p.add(b6); f.add(p); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
/** Component initialization */ private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(bd); ThreadPanel tp1 = new ThreadPanel("Passengers", Color.blue); ThreadPanel tp2 = new ThreadPanel("Car(2)", Color.blue); ThreadPanel tp3 = new ThreadPanel("Car(3)", Color.blue); NumberCanvas nc1 = new NumberCanvas("Platform"); NumberCanvas nc2 = new NumberCanvas("In Car(2)"); NumberCanvas nc3 = new NumberCanvas("In Car(3)"); Panel p1 = new Panel(); p1.setLayout(new BorderLayout()); Panel p2 = new Panel(); p2.setLayout(new BorderLayout()); Panel p3 = new Panel(); p3.setLayout(new BorderLayout()); p1.add(nc1, BorderLayout.CENTER); p1.add(tp1, BorderLayout.SOUTH); p2.add(nc2, BorderLayout.CENTER); p2.add(tp2, BorderLayout.SOUTH); p3.add(nc3, BorderLayout.CENTER); p3.add(tp3, BorderLayout.SOUTH); Panel grid = new Panel(); grid.setLayout(new GridLayout(1, 3)); grid.add(p1); grid.add(p2); grid.add(p3); contentPane.add(grid, BorderLayout.CENTER); // construct threads, monitor & go button final Controller c = new Controller(nc1); final PlatformAccess pa = new PlatformAccess(); Button go = new Button("Go Now"); go.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { c.goNow(); } }); contentPane.add(go, BorderLayout.SOUTH); tp1.start(new Passengers(c)); tp2.start(new CoasterCar(2, c, pa, nc2)); tp3.start(new CoasterCar(3, c, pa, nc3)); this.setSize(new Dimension(470, 350)); this.setTitle("Roller Coaster Laboratory Exercise"); }
public void actionPerformed(ActionEvent ae) { String s1 = ae.getActionCommand(); if (s1.equals("Calendar")) { // DatePicker dp=new DatePicker(f); // dp.displayDate(); // f.getContentPane().add(p); b3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { t6.setText(new DatePicker(f).setPickedDate()); } }); } else if (s1.equals("LogOut")) { f.dispose(); start p = new start(); p.method(); } else if (s1.equals("Search")) { try { String data = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery("select * from mprofile where Manager_Id='" + data + "' "); while (rs.next()) { String a2 = rs.getString(1); t2.setText(a2); String a3 = rs.getString(2); t3.setText(a3); String a4 = rs.getString(3); t4.setText(a4); String a5 = rs.getString(4); t5.setText(a5); String a6 = rs.getString(6); t6.setText(a6); String a7 = rs.getString(7); t7.setText(a7); String a8 = rs.getString(8); t8.setText(a8); String a9 = rs.getString(9); t9.setText(a9); String a10 = rs.getString(10); t10.setText(a10); p.add(l3); p.add(t2); p.add(l4); p.add(t3); p.add(l5); p.add(t4); p.add(l6); p.add(t5); p.add(l7); p.add(c1); p.add(c2); p.add(l8); p.add(t6); p.add(l9); p.add(t7); p.add(l10); p.add(t8); p.add(l11); p.add(t9); p.add(l12); p.add(t10); p.add(b2); p.add(b3); p.add(b4); } } catch (Exception e) { } } else if (s1.equals("Update")) { String y2 = t2.getText(); String y3 = t3.getText(); String update_id = t4.getText(); String y4 = t5.getText(); String y6 = t6.getText(); String y7 = t7.getText(); String y8 = t8.getText(); String y9 = t9.getText(); String y10 = t10.getText(); try { String y = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); PreparedStatement ps = con.prepareStatement( "update mprofile set Location=? , E_Mail_Id=? ,Contact_No =?, Address=?, D_O_B=?,Gender=?, Password=?, Manager_Id=?,manager_father=?,manager_name=? where Manager_Id='" + y + "' "); ps.setString(1, y10); ps.setString(2, y9); ps.setString(3, y8); ps.setString(4, y7); ps.setString(5, y6); ps.setString(6, g); ps.setString(7, y4); ps.setString(8, update_id); ps.setString(9, y3); ps.setString(10, y2); ps.executeUpdate(); JOptionPane.showMessageDialog(p, "data has been updated"); f.dispose(); project p = new project(); p.method(); } catch (Exception e) { System.out.println(e); } } else if (s1.equals("Close")) { f.dispose(); } else { f.dispose(); project p = new project(); p.method(); } }