First, you want to start with a JFrame, not a console:
JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true);
Then use the Charles code to help you get started with JButton.
JButton button = new JButton(); ... set properties here... button.setText("blah");
Then, to activate the action, add a listener, again from Charles's message.
button.addMouseListener(new MouseListener() { override methods here to do what you want. }
source share