










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











So far, we have done sequential programming This means we start at the beginning of main() and go one line at a time (See: Sequential.java) higher up runs first
Exceptions no longer obeyed this rule:
The basis of GUIs are windows (or frames) To make a window, you need to make a JFrame object
There are a few other methods that you should normally use to setup the JFrame window: setSize(int width, int height) - Makes the window size width by height pixels setDefaultCloseOperation() - Sets up what clicking the X on top does (default behavior hides the program!) (See: ClosingWindow.java) Docsity.com
The previous code example is rather worthless since the button does not do anything In order to get a useful button you need to implement the ActionListener interface So far we have not strayed too far from sequential programming, but now we will (Note: main() returning does not end the program) Docsity.com
Let's make a class that implements the ActionListener interface: Then we need to override the actionPerfromed() method: (See: RanomDigit.java)
JLabel is simply some text in a window that does not interact with the user, used for...
(See: MakeItStop.java)
ActionListeners work when you press a button, but it is much more fun to work with a mouse You can implement MouseListener to get information from the mouse: This works very similar to ActionListener, except with more methods