List of usage examples for javax.swing JButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:Main.java
Main() { JButton button = new JButton("Click to chooose the first point"); add(button); button.addActionListener(this); }
From source file:EventQueuePanel.java
EventQueuePanel() { JButton button = new JButton("Draw line"); add(button); button.addActionListener(this); }
From source file:TabComponent.java
public TabComponent(String title, JTabbedPane pane) { this.pane = pane; setOpaque(false);/*from w w w. j a va 2 s.c o m*/ JLabel label = new JLabel(title); add(label); JButton button = new JButton("Close"); button.setPreferredSize(new Dimension(50, 10)); button.addActionListener(this); add(button); }
From source file:AddressDialog.java
private void init() { this.getContentPane().setLayout(new FlowLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final AddressDialog dialog = new AddressDialog(this, false); JButton button = new JButton("Show Dialog"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dialog.setSize(250, 120);/*from w w w . j a va 2s . c o m*/ dialog.setVisible(true); } }); this.getContentPane().add(button); }
From source file:Main.java
public TextPaneAttributes() { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, 0, standard, true); MutableAttributeSet keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.red); StyleConstants.setItalic(keyWord, true); textPane.setText("this is a test. \nthis is a four."); doc.setCharacterAttributes(0, 3, keyWord, false); doc.setCharacterAttributes(19, 4, keyWord, false); try {//from w w w . java 2 s . co m doc.insertString(0, "Start of text\n", null); doc.insertString(doc.getLength(), "End of text\n", keyWord); } catch (Exception e) { } MutableAttributeSet selWord = new SimpleAttributeSet(); StyleConstants.setForeground(selWord, Color.RED); StyleConstants.setItalic(selWord, true); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); add(scrollPane); JButton toggleButton = new JButton("Find 'four'"); toggleButton.addActionListener(e -> { int index = textPane.getText().indexOf("four"); StyledDocument doc1 = textPane.getStyledDocument(); doc1.setCharacterAttributes(index, 4, selWord, false); }); add(toggleButton, BorderLayout.SOUTH); }
From source file:TicTacToe.java
public void init() { JPanel p = new JPanel(); p.setLayout(new GridLayout(2, 2)); p.add(new JLabel("Rows", JLabel.CENTER)); p.add(rows);//from w w w . j a v a2 s .c o m p.add(new JLabel("Columns", JLabel.CENTER)); p.add(cols); Container cp = getContentPane(); cp.add(p, BorderLayout.NORTH); JButton b = new JButton("go"); b.addActionListener(new BL()); cp.add(b, BorderLayout.SOUTH); }
From source file:JOptionDemo.java
JOptionDemo(String s) { super(s);/*from w w w . ja va2 s .co m*/ Container cp = getContentPane(); cp.setLayout(new FlowLayout()); JButton b = new JButton("Give me a message"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(JOptionDemo.this, "This is your message: etaoin shrdlu", "Coded Message", JOptionPane.INFORMATION_MESSAGE); } }); cp.add(b); b = new JButton("Goodbye!"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); cp.add(b); // size the main window pack(); }
From source file:Test.java
public Test() { this.setBounds(100, 100, 200, 100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createRaisedSoftBevelBorder()); this.setLayout(new FlowLayout()); JButton exitButton = new JButton("Exit"); panel.add(exitButton);// w ww .j a va2s . co m this.add(panel); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); }
From source file:Test.java
public Test() { this.setBounds(100, 100, 200, 100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED)); // panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED)); this.setLayout(new FlowLayout()); JButton exitButton = new JButton("Exit"); panel.add(exitButton);/*from www.j av a 2 s .com*/ this.add(panel); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); }
From source file:Main.java
public Main() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(buildDemoModel()); JPanel buttonsPanel = new JPanel(); JButton saveButton = new JButton("Capture state"); saveButton.addActionListener(e -> expansionState = saveExpansionState(tree)); JButton loadButton = new JButton("Load state"); loadButton.addActionListener(e -> { loadExpansionState(tree, expansionState); expansionState = saveExpansionState(tree); });/* w w w .j av a 2 s . com*/ buttonsPanel.add(saveButton); buttonsPanel.add(loadButton); JPanel content = new JPanel(new BorderLayout()); content.add(buttonsPanel, BorderLayout.SOUTH); content.add(new JScrollPane(tree), BorderLayout.CENTER); frame.add(content); frame.pack(); frame.setVisible(true); }