List of usage examples for java.awt Button addActionListener
public synchronized void addActionListener(ActionListener l)
From source file:width.java
public void init() { Button button = new Button("Clear"); add(label);//from ww w . java2s . c om add(button); button.addActionListener(this); add(new Label("(My name is " + getParameter("name") + ".)", Label.LEFT)); }
From source file:MessageViewer.java
protected void addToolbar() { GridBagConstraints gb = new GridBagConstraints(); gb.gridheight = 1;/* w ww.jav a 2s .c o m*/ gb.gridwidth = 1; gb.fill = GridBagConstraints.NONE; gb.anchor = GridBagConstraints.WEST; gb.weightx = 0.0; gb.weighty = 0.0; gb.insets = new Insets(4, 4, 4, 4); // structure button gb.gridwidth = GridBagConstraints.REMAINDER; // only for the last one Button b = new Button("Structure"); b.addActionListener(new StructureAction()); add(b, gb); }
From source file:AlphaTest.java
/** * Helper method to add a Button to the UI. */// www.j a v a 2 s .c o m protected void addButton(final String szText) { Button button = new Button(szText); button.addActionListener(this); add(button); }
From source file:Sampler.java
private void createUI() { setFont(new Font("Serif", Font.PLAIN, 12)); setLayout(new BorderLayout()); // Set our location to the left of the image frame. setSize(200, 350);/* w ww . ja v a2 s .c o m*/ Point pt = mImageFrame.getLocation(); setLocation(pt.x - getSize().width, pt.y); final Checkbox accumulateCheckbox = new Checkbox("Accumulate", false); final Label statusLabel = new Label(""); // Make a sorted list of the operators. Enumeration e = mOps.keys(); Vector names = new Vector(); while (e.hasMoreElements()) names.addElement(e.nextElement()); Collections.sort(names); final java.awt.List list = new java.awt.List(); for (int i = 0; i < names.size(); i++) list.add((String) names.elementAt(i)); add(list, BorderLayout.CENTER); // When an item is selected, do the corresponding transformation. list.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() != ItemEvent.SELECTED) return; String key = list.getSelectedItem(); BufferedImageOp op = (BufferedImageOp) mOps.get(key); BufferedImage source = mSplitImageComponent.getSecondImage(); boolean accumulate = accumulateCheckbox.getState(); if (source == null || accumulate == false) source = mSplitImageComponent.getImage(); String previous = mImageFrame.getTitle() + " + "; if (accumulate == false) previous = ""; mImageFrame.setTitle(previous + key); statusLabel.setText("Performing " + key + "..."); list.setEnabled(false); accumulateCheckbox.setEnabled(false); BufferedImage destination = op.filter(source, null); mSplitImageComponent.setSecondImage(destination); mSplitImageComponent.setSize(mSplitImageComponent.getPreferredSize()); mImageFrame.setSize(mImageFrame.getPreferredSize()); list.setEnabled(true); accumulateCheckbox.setEnabled(true); statusLabel.setText("Performing " + key + "...done."); } }); Button loadButton = new Button("Load..."); loadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { FileDialog fd = new FileDialog(Sampler.this); fd.show(); if (fd.getFile() == null) return; String path = fd.getDirectory() + fd.getFile(); mSplitImageComponent.setImage(path); mSplitImageComponent.setSecondImage(null); // Utilities.sizeContainerToComponent(mImageFrame, // mSplitImageComponent); mImageFrame.validate(); mImageFrame.repaint(); } }); Panel bottom = new Panel(new GridLayout(2, 1)); Panel topBottom = new Panel(); topBottom.add(accumulateCheckbox); topBottom.add(loadButton); bottom.add(topBottom); bottom.add(statusLabel); add(bottom, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { mImageFrame.dispose(); dispose(); System.exit(0); } }); }
From source file:WebCrawler.java
public void init() { // set up the main UI panel panelMain = new Panel(); panelMain.setLayout(new BorderLayout(5, 5)); // text entry components Panel panelEntry = new Panel(); panelEntry.setLayout(new BorderLayout(5, 5)); Panel panelURL = new Panel(); panelURL.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); Label labelURL = new Label("Starting URL: ", Label.RIGHT); panelURL.add(labelURL);/* w ww . j a va2s. c om*/ textURL = new TextField("", 40); panelURL.add(textURL); panelEntry.add("North", panelURL); Panel panelType = new Panel(); panelType.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); Label labelType = new Label("Content type: ", Label.RIGHT); panelType.add(labelType); choiceType = new Choice(); choiceType.addItem("text/html"); choiceType.addItem("audio/basic"); choiceType.addItem("audio/au"); choiceType.addItem("audio/aiff"); choiceType.addItem("audio/wav"); choiceType.addItem("video/mpeg"); choiceType.addItem("video/x-avi"); panelType.add(choiceType); panelEntry.add("South", panelType); panelMain.add("North", panelEntry); // list of result URLs Panel panelListButtons = new Panel(); panelListButtons.setLayout(new BorderLayout(5, 5)); Panel panelList = new Panel(); panelList.setLayout(new BorderLayout(5, 5)); Label labelResults = new Label("Search results"); panelList.add("North", labelResults); Panel panelListCurrent = new Panel(); panelListCurrent.setLayout(new BorderLayout(5, 5)); listMatches = new List(10); panelListCurrent.add("North", listMatches); labelStatus = new Label(""); panelListCurrent.add("South", labelStatus); panelList.add("South", panelListCurrent); panelListButtons.add("North", panelList); // control buttons Panel panelButtons = new Panel(); Button buttonSearch = new Button(SEARCH); buttonSearch.addActionListener(this); panelButtons.add(buttonSearch); Button buttonStop = new Button(STOP); buttonStop.addActionListener(this); panelButtons.add(buttonStop); panelListButtons.add("South", panelButtons); panelMain.add("South", panelListButtons); add(panelMain); setVisible(true); repaint(); // initialize search data structures vectorToSearch = new Vector(); vectorSearched = new Vector(); vectorMatches = new Vector(); // set default for URL access URLConnection.setDefaultAllowUserInteraction(false); }
From source file:QuoteServerThread.java
public void init() { //Initialize networking stuff. String host = getCodeBase().getHost(); try {/*from w w w . j ava 2 s . co m*/ address = InetAddress.getByName(host); } catch (UnknownHostException e) { System.out.println("Couldn't get Internet address: Unknown host"); // What should we do? } try { socket = new DatagramSocket(); } catch (IOException e) { System.out.println("Couldn't create new DatagramSocket"); return; } //Set up the UI. GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridBag); Label l1 = new Label("Quote of the Moment:", Label.CENTER); c.anchor = GridBagConstraints.SOUTH; c.gridwidth = GridBagConstraints.REMAINDER; gridBag.setConstraints(l1, c); add(l1); display = new Label("(no quote received yet)", Label.CENTER); c.anchor = GridBagConstraints.NORTH; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; gridBag.setConstraints(display, c); add(display); Label l2 = new Label("Enter the port (on host " + host + ") to send the request to:", Label.RIGHT); c.anchor = GridBagConstraints.SOUTH; c.gridwidth = 1; c.weightx = 0.0; c.weighty = 1.0; c.fill = GridBagConstraints.NONE; gridBag.setConstraints(l2, c); add(l2); portField = new TextField(6); gridBag.setConstraints(portField, c); add(portField); Button button = new Button("Send"); gridBag.setConstraints(button, c); add(button); portField.addActionListener(this); button.addActionListener(this); }
From source file:MultiView.java
protected void addCanvas3D(Canvas3D c3d) { add(c3d);//w w w . ja v a 2 s . c om // IFF we have created the first view // also add a button to allow more views // to be created if (m_nNumViews == 1) { Button button = new Button("Add View"); button.addActionListener(this); add(button); } doLayout(); }
From source file:net.sf.freecol.FreeCol.java
public static void startYourAddition() throws FontFormatException, IOException { Frame mainFrame;/*w w w. j a v a 2s.c o m*/ Frame mainFrame2; TextField t1; TextField t2; TextField t3; TextField t4; Frame mainFrame3 = new Frame("Haha, am i middle?"); mainFrame = new Frame("Haha, am I right?!"); mainFrame.setSize(400, 400); mainFrame.setLayout(null); t1 = new TextField("Enter here"); t1.setBounds(160, 200, 150, 50); t2 = new TextField("What grade do we deserve?"); t3 = new TextField("Enter here"); t3.setBounds(160, 200, 150, 50); t4 = new TextField("What letter grade do we deserve?"); Button b = new Button("click ----->"); b.setBounds(30, 250, 130, 30); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { t2.setText("I think you meant 100"); } }); Button c = new Button("Submit"); c.setBounds(150, 250, 80, 30); c.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String in = t1.getText(); if (in.equals("100")) { t1.setText("Correct"); t1.setEditable(false); t1.setBackground(new Color(95, 216, 109)); if (t3.getText().equals("Correct")) { mainFrame3.setVisible(true); } } else { t1.setText("Wrong"); t1.setBackground(new Color(214, 81, 96)); } } }); t2.setBounds(160, 0, 175, 100); t2.setEditable(false); mainFrame.add(b); mainFrame.add(c); mainFrame.add(t1); mainFrame.add(t2); mainFrame.setLocation(1280, 0); mainFrame.setVisible(true); ///////////////The left area below and above is right mainFrame2 = new Frame("Haha, am i left?"); mainFrame2.setSize(400, 400); mainFrame2.setLayout(null); Button b2 = new Button("click ----->"); b2.setBounds(30, 250, 130, 30); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { t4.setText("I think you meant A"); } }); Button c2 = new Button("Submit"); c2.setBounds(150, 250, 80, 30); c2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String in = t3.getText(); if (in.equals("A")) { t3.setText("Correct"); t3.setEditable(false); t3.setBackground(new Color(95, 216, 109)); if (t1.getText().equals("Correct")) { mainFrame3.setVisible(true); } } else { t3.setText("Wrong"); t3.setBackground(new Color(214, 81, 96)); } } }); t4.setBounds(120, 0, 220, 100); t4.setEditable(false); mainFrame2.add(b2); mainFrame2.add(c2); mainFrame2.add(t3); mainFrame2.add(t4); mainFrame2.setVisible(true); //Overall correct mainFrame3.setSize(400, 400); mainFrame3.setLayout(null); mainFrame3.setLocation(640, 420); mainFrame3.setBackground(new Color(95, 216, 109)); TextField t6 = new TextField("Soooooo give us an A!!!"); t6.setBounds(160, 200, 200, 50); t6.setBackground(new Color(102, 136, 232)); mainFrame3.add(t6); }
From source file:width.java
public void init() { GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridBag);//from ww w . j ava 2s .c om Label receiverLabel = new Label("Receiver name:", Label.RIGHT); gridBag.setConstraints(receiverLabel, c); add(receiverLabel); nameField = new TextField(getParameter("RECEIVERNAME"), 10); c.fill = GridBagConstraints.HORIZONTAL; gridBag.setConstraints(nameField, c); add(nameField); nameField.addActionListener(this); Button button = new Button("Send message"); c.gridwidth = GridBagConstraints.REMAINDER; //end row c.anchor = GridBagConstraints.WEST; //stick to the //text field c.fill = GridBagConstraints.NONE; //keep the button //small gridBag.setConstraints(button, c); add(button); button.addActionListener(this); status = new TextArea(5, 60); status.setEditable(false); c.anchor = GridBagConstraints.CENTER; //reset to the default c.fill = GridBagConstraints.BOTH; //make this big c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(status, c); add(status); myName = getParameter("NAME"); Label senderLabel = new Label("(My name is " + myName + ".)", Label.CENTER); c.weightx = 0.0; c.weighty = 0.0; gridBag.setConstraints(senderLabel, c); add(senderLabel); newline = System.getProperty("line.separator"); }
From source file:Align_Projections.java
Button addButton(String label) { Button b = new Button(label); b.addActionListener(this); b.addKeyListener(IJ.getInstance());/*from w ww . ja v a 2 s.c om*/ add(b); return b; }