Swing - GUI Flashcards

1
Q

event driven programming

A

flow of the program is determined by events such as user actions, sensor outputs, or messages from other programs or threads

  • signal and response approach
  • exception handling is an example
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a GUI

A

graphical user interfaace - windowing system that interacts with the user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

awt

A

abstract window tool kit - original package in java for creating gui - swing now used generally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

event

A

an object that acts as a signal to another object - called a listener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

firing an event

A

sending an event - often a gui component - e.g. button clicked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

listener

A

listener object performs some action in response to the event - one big listener or individual listeners

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

example of events

A

exception objects - throwing of an exception - the listener for an exception is the catch block that catches the event

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

event handlers

A

methods that specify what will happen when the events of various kinds are received by it - the programmer using the listener object will define or redefine these event-handlers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

difference between event driven programming and what we’ve been doing…

A
  • objects are created that can fire events and listener objects are created that can react to these events
  • events determine the order in which things happen

in particular - methods are defineed that will never be explicitly invoked in any program - methods are invoked when an event signals that the method needs to be called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

JFrame

A

a simple window consists of an object of this class
- border and usual 3 buttons

JFrame newFrame = new JFrame (size, size);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

adding to and setting visibility of JFrame and setting close

A

newFrame.add(endButton);
newFrame.setVisible(true);
newFrame.serDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

pixel

A

smallest unit of space on screen - size and position of swing objs measured in pixels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what happens if you don’t program

A

default - hide on close

- doesnt close the program - memory and battery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JButton

A

JButton button = new JButton(“Press me”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

adding listeners to buttongs

A
EndingListener buttonEar = newEndingListener());
button.addActionListener(buttonEar);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

action listener method definition

A
public void actionPerformed(ActionEvent e)
{
//stuff that gets done
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

extending the JFrame

A
public class windowOne extends JFrame{
    public windowOne(){
         super();
     ///stuff

}
}

create another class for the listeners

18
Q

JLabel

A
JLabel greeting = new JLabel("Hello");
add(greeting); //if the program is an extension
19
Q

can you colour a JFrame directly

A

no - must color a content pane of the jframe

  • getContentPane().setBackground(Color);
  • e.g. Color.BLACK;
20
Q

three main layouts

A

BorderLayout
FlowLayout - default
GridLayout

21
Q

borderlayout

A
setLayout(new BorderLayout());
add(label1, BorderLayout.South);
22
Q

flowlayout

A

setLayout(new FlowLayout()); - arranges compnents one after the other from left to right - order - order of added

23
Q

gridlayout

A
setLayout(new GridLayout(rows, columns));
added in grid from left to right - top from filled first - positions cannot be skipped
24
Q

Panel

A
class that serves as a simpler container
JPanel somePanel = new JPanel();
25
Q

the container class

A
  • in awt

- Any class that is a descendent class of the class Container is considered to be a container class

26
Q

the JComponent class

A

Any JComponentobject or componentcan be added to any container class object

27
Q

the three objects that make up almost every gui using swing container classes

A

the container
components
layout manager

28
Q

menu

A
JMenu
- choice menu is called a menu item - object of class JMenuItem
29
Q

menu bar

A
container for menus 
JMenuBar bar = new JMenuBar();
30
Q

2 different ways to add a menu bar to a JFrame

A

1 - Using the setJMenuBar method: setJMenuBar(bar);

2 - Using the add method – which can be used to add a menu bar to a JFrame or any other container

31
Q

The classes JButtonand JMenuItemare derived classes of the abstract class named…

A

AbstractButton

32
Q

what happens when the user clicks a button

A
  • action event becomes an argument to an actionPerformed method
  • action event contains a string instance var called the action command for the button or menu item
  • default value for this string - the string attached to the button
  • This string can be retrieved with the getActionCommand method e.getActionCommand()
33
Q

the setActionCommand

A

can be used to change the action command for a component - This is especially useful when two or more buttons or menu items have the same default action command strings

34
Q

having listeners as inner classes

A
public class ListenerOne implements ActionListener{
public void actionPerformed(ActionEvent e){
     //stuffs
}
}
35
Q

textfields

A
  • One line display - used to get one line text input from user
  • JTextField name = new JTextField(“Enter name here.”, 30);
36
Q

getText, setText

A

getText: can read the text in the text field
setText: can be used to display new text string in a txt field

37
Q

textarea

A

JTextArea textA = new JTextArea(“String”, lines, chars per line);

38
Q

txtarea.setLineWrap(boolean);

A

to see or not to see characters that exceed the limit

39
Q

txtarea.setEditable(boolean)

A

only the gui can change this - not the user

40
Q

em space

A

number of characters that a textfield or area can use is the number of em spaces - space needed for “M”