Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
28 Cards in this Set
- Front
- Back
frame
|
a window with a title bar
|
|
create a frame
|
JFrame frame = new JFrame();
|
|
set size of frame
|
final int FRAME_WIDTH = 300; final int FRAME_HEIGHT = 400; frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); If you omit this step the frame will be 0 by 0 pixels
|
|
set title for frame
|
frame.setTitle("An empty frame");
|
|
when the user closes frame, program exits
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
make the frame visible
|
frame.setVisible(true);
|
|
Swing package
|
java graphical user-interface library in java
|
|
panel
|
a container for other user-interface components. Use a JPanel to group multiple user-interface components together.
|
|
Adding to Panel
|
JPanel panel = new JPanel(); panel.add(button); panel.add(label); frame.add(panel);
|
|
Constructing panel components
|
JButton button = new JButton("Click me!"); JLabel label = new JLabel("Hello, World!");
|
|
What to do in frame constructor
|
Initialize variables in the constructor, frame size also in the frame constructor
|
|
graphical user interface
|
the user is in control. The user can use both the mouse and the keyboard and can manipulate many parts of the user interface in any desired order.
|
|
User-interface events
|
include key presses, mouse moves, button clicks, menu selections, and so on.
|
|
Event
|
whenever the user of a graphical program types characters or uses the mouse anywhere inside one of the windows of the program, the program receives a notification
|
|
Event listender objects
|
every program must indicate which events a program needs to receive.
|
|
Event source
|
need one to install a listener. Event sources report on events. When an event occurs, the event source notifies all event listeners.
|
|
Button listeners
|
must belong to a class that implements the ActionListener interface. Ignore the event parameter variable of the actionPerformed method.
|
|
Once a button listen has been declared
|
we need to construct an object of the class and admit to the button: ActionListener listener = new ClickListener(); button.addActionListener(listener);
|
|
inner class
|
class that is declared inside another class. Advantages to this are 1) listener classes tend to be very short. You can put it where it is needed, without cluttering up the remainder of the project. 2) inner class methods can access instance variables and methods of the surrounding class. This is particularly useful when implementing event handlers. It allows the inner class to access variables without having to receive them as constructor or method arguments.
|
|
inner classes can be declared
|
completely inside a method
|
|
Entity is anonymous
|
if it does not have a name.
|
|
JTextField
|
provides a text field for reading a single line of text. Need to supply the width. final int FIELD_WIDTH = 10; rateField = new JTextField(FIELD_WIDTH);
|
|
JTextArea
|
to show multiple lines of text.
|
|
in order to display a drawing
|
provide a class that extends JComponent. Then override the paintComponent method.
|
|
paintComponent
|
place drawing instructions here. This method is called whenever the component needs to be repainted. The method is called when the window is resized or when it is shown again when it is hidden. This method receives an object of type Graphics. The graphics object holds the graphic state (color, fonts, etc) used for drawing. Also, it has methods for drawing geometric shapes.
|
|
x, y coordinates
|
the graphics object draws x normally, but y is inverted. So the point 3, 15 would draw 3 to the right and 15 down.
|
|
Graphics object methods
|
drawOval, drawLine, drawString, etc.
|
|
Change color
|
you can either make a new Color object and specify the RGB values. Or you use g.setColor(Color.YELLOW) for some prebuilt options.
|