// Uppgift 1 import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class Graphics implements ActionListener{ public static void main(String[] args) { new Graphics(); // Object of this class } public Graphics() { JFrame frame = new JFrame("Frame"); frame.setVisible(true); frame.setSize(100, 100); JButton button = new JButton("hej"); JButton button2 = new JButton("hj"); frame.add(button); frame.add(button2, BorderLayout.NORTH); // Standard layout of JFrame is BorderLayout button.addActionListener(this); button2.addActionListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // So the process is terminated when user closes } @Override public void actionPerformed(ActionEvent e) { if(((JButton) e.getSource()).getText().equals("hej")){ System.out.println("hej"); } } }