MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish...
-
Upload
lindsey-york -
Category
Documents
-
view
215 -
download
1
Transcript of MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish...
![Page 1: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/1.jpg)
MSc IT
Programming Methodology (2)
![Page 2: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/2.jpg)
Which printer [a] LPT1 or [b] LPT2?:
How many copies do you wish to print?:
[P]rint now or [C]ancel?:
Print all pages (y/n)?:
a
2
y
C
![Page 3: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/3.jpg)
![Page 4: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/4.jpg)
Graphics and event-driven programs
Learning objectives
• identify and use some of the common components of the Java Swing package;
• program graphics components to handle mouse-click events;
• describe the role of layout managers;
• use the FlowLayout and BorderLayout managers;
• make use of compound containers.
![Page 5: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/5.jpg)
Swing vs AWT
![Page 6: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/6.jpg)
AWTSwing
heavyweight
lightweight
![Page 7: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/7.jpg)
Swing Components..
![Page 8: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/8.jpg)
![Page 9: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/9.jpg)
The SmileyFace program…
![Page 10: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/10.jpg)
public class RunSmileyFace{ public static void main(String[ ] args) { new SmileyFace(); }}
![Page 11: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/11.jpg)
JFrame
SmileyFace is a kind of JFrame
JFrame
SmileyFace
SmileyFace( )
paint( )
![Page 12: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/12.jpg)
public class SmileyFace
import java.awt.*;import javax.swing.*;
{ public SmileyFace() { // initialise the screen }
public void paint(Graphics g) { // draw onto the screen }}
extends JFrame
![Page 13: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/13.jpg)
The SmileyFace constructor..
![Page 14: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/14.jpg)
public SmileyFace()
{
setTitle("Smiley Face");
}
![Page 15: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/15.jpg)
public SmileyFace()
{
setTitle("Smiley Face");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(250,220);
setLocation(300,300);
getContentPane().setBackground(Color.yellow);
}
![Page 16: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/16.jpg)
public SmileyFace()
{
setTitle("Smiley Face");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(250,220);
setLocation(300,300);
getContentPane().setBackground(Color.yellow);
setVisible(true);
}
![Page 17: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/17.jpg)
The paint method..
![Page 18: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/18.jpg)
public void paint(Graphics g)
{
super.paint(g);
}
g.drawOval(85,75,75,75); g.setColor(Color.blue); g.drawOval(100,95,10,10); g.drawOval(135,95,10,10);
g.drawArc(102,115,40,25,0,-180); g.drawString("Smiley Face", 90,175);
g.setColor(Color.red);
Calls the paint method of the superclass - JFrame
![Page 19: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/19.jpg)
public class RunSmileyFace{ public static void main(String[ ] args) { new SmileyFace(); }}
![Page 20: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/20.jpg)
The ChangingFace class…
![Page 21: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/21.jpg)
JButton JButton
boolean
![Page 22: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/22.jpg)
import javax.swing.*;import java.awt.*;
public class ChangingFace extends JFrame {
public ChangingFace() { // code goes here }
public void paint(Graphics g) { // code goes here }
}
private JButton happyButton = new JButton("Smile");private JButton sadButton = new JButton("Frown");
private boolean isHappy = true;
![Page 23: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/23.jpg)
The ChangingFace constructor..
![Page 24: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/24.jpg)
public ChangingFace()
{
setTitle("Changing Face");
getContentPane().setBackground(Color.yellow);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(250, 200);
setLocation(300,300);
setVisible(true);
}
setLayout(new FlowLayout());add(happyButton);
add(sadButton);
![Page 25: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/25.jpg)
The paint method..
![Page 26: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/26.jpg)
public void paint(Graphics g){ super.paint(g); g.setColor(Color.red); g.drawOval(85,45,75,75); g.setColor(Color.blue); g.drawOval(100,65,10,10); g.drawOval(135,65,10,10); g.drawString("Changing Face", 80,155);
}
if(isHappy == true){ g.drawArc(102,85,40,25,0,-180);}else{ g.drawArc(102,85,40,25,0,180);}
![Page 27: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/27.jpg)
![Page 28: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/28.jpg)
How do we get the program to monitor our buttons for mouse-click events ?
![Page 29: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/29.jpg)
Give each button a listener!
![Page 30: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/30.jpg)
public ChangingFace()
{
setTitle("Changing Face");
setLayout(new FlowLayout());
add(happyButton);
add(sadButton);
getContentPane().setBackground(Color.yellow);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(250, 200);
setLocation(300,300);
setVisible(true);
}
happyButtonsadButton
.addActionListener( ); this.addActionListener( ); this
code for responding to mouse clicks is in this class
![Page 31: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/31.jpg)
import javax.swing.*;import java.awt.*;
public class ChangingFace extends JFrame {
public ChangingFace() { // code goes here } public void paint(Graphics g) { // code goes here }
}
private JButton happyButton = new JButton("Smile");private JButton sadButton = new JButton("Frown");
private boolean isHappy = true;
public void actionPerformed(ActionEvent e){ // code goes here}
This method is where we write the code for responding to button clicks
![Page 32: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/32.jpg)
import javax.swing.*;import java.awt.*;
public class ChangingFace extends JFrame {
public ChangingFace() { // code goes here } public void paint(Graphics g) { // code goes here }
}
private JButton happyButton = new JButton("Smile");private JButton sadButton = new JButton("Frown");
private boolean isHappy = true;
public void actionPerformed(ActionEvent e){ // code goes here}
implements ActionListener import java.awt.event.*;
This special kind of Class acts a bit like a contract.
![Page 33: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/33.jpg)
import javax.swing.*;import java.awt.*;
public class ChangingFace extends JFrame {
public ChangingFace() { // code goes here } public void paint(Graphics g) { // code goes here }
}
private JButton happyButton = new JButton("Smile");private JButton sadButton = new JButton("Frown");
private boolean isHappy = true;
public void actionPerformed(ActionEvent e){ // code goes here}
implements ActionListener import java.awt.event.*;
This key word indicates that we have met that contract.
![Page 34: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/34.jpg)
import javax.swing.*;import java.awt.*;
public class ChangingFace extends JFrame {
public ChangingFace() { // code goes here } public void paint(Graphics g) { // code goes here }
}
private JButton happyButton = new JButton("Smile");private JButton sadButton = new JButton("Frown");
private boolean isHappy = true;
public void actionPerformed(ActionEvent e){ // code goes here}
implements ActionListener import java.awt.event.*;
![Page 35: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/35.jpg)
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == happyButton)
{
isHappy = true;
repaint();
}
if(e.getSource() == sadButton)
{
isHappy = false;
repaint();
}
}
![Page 36: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/36.jpg)
public class RunChangingFace
{
public static void main(String[] args)
{
new ChangingFace();
}
}
Running the application
![Page 37: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/37.jpg)
Another interactive graphics class…………
![Page 38: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/38.jpg)
![Page 39: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/39.jpg)
![Page 40: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/40.jpg)
![Page 41: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/41.jpg)
JFrame
JTextField
JButton
JLabel
![Page 42: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/42.jpg)
import javax.swing.*;import java.awt.event.*;import java.awt.*;
public class PushMe extends JFrame implements ActionListener{ private JTextField myTextField = new JTextField(15); private JButton myButton = new JButton("please push me"); private JLabel myLabel = new JLabel("Enter some text and push the button", JLabel.CENTER); public PushMe() { // code goes here }
public void actionPerformed(ActionEvent e) { // code goes here }}
![Page 43: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/43.jpg)
public PushMe()
{
setTitle("Push Me");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(220,120);
setLocation(400, 300);
add(myTextField);
add(myButton);
add(myLabel);
myButton.addActionListener(this);
setVisible(true);
}
![Page 44: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/44.jpg)
public void actionPerformed(ActionEvent e){
}
String myText;myText = myTextField.getText();
myLabel.setText("You entered: " + myText);
myTextField
myLabel
![Page 45: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/45.jpg)
A GUI for the Oblong class …
![Page 46: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/46.jpg)
JTextArea
JButton
JLabel
JTextField JLabel JTextField
![Page 47: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/47.jpg)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class OblongGUI extends JFrame implements ActionListener
{
private Oblong myOblong = new Oblong(0,0);
private JLabel lengthLabel = new JLabel("Length");
private JTextField lengthField = new JTextField(5);
private JLabel heightLabel = new JLabel("Height");
private JTextField heightField = new JTextField(5);
private JButton calcButton = new JButton("Calculate");
private JTextArea displayArea = new JTextArea(2,20);
// methods go here
}
![Page 48: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/48.jpg)
public OblongGUI(){ setTitle("Oblong GUI"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); setSize(240, 135); setLocation(300,300);
add(lengthLabel); add(lengthField); add(heightLabel); add(heightField); add(calcButton); add(displayArea); calcButton.addActionListener(this); setVisible(true);}
![Page 49: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/49.jpg)
public void actionPerformed(ActionEvent e){ String lengthEntered = lengthField.getText(); String heightEntered = heightField.getText(); if(lengthEntered.length() == 0 || heightEntered.length() == 0) { displayArea.setText("Length and height must be entered"); } else { myOblong.setLength( Double.parseDouble(lengthEntered) ); myOblong.setHeight( Double.parseDouble(heightEntered) ); displayArea.setText("The area of the oblong is " + myOblong.calculateArea() + "\n" + "The perimeter of the oblong is " + myOblong.calculatePerimeter()); } }}
![Page 50: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/50.jpg)
A metric converter
![Page 51: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/51.jpg)
JFrame
JPanel
JPanel
JPanel
inchCmPanel
mileKmPanel
poundKgPanel
![Page 52: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/52.jpg)
Layout policies - FlowLayout
![Page 53: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/53.jpg)
Layout policies - BorderLayout
![Page 54: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/54.jpg)
Compound containers
![Page 55: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/55.jpg)
JPanel
JPanel
inchCmPanel
inchCmButtons
inchCmButtons.setLayout(new BorderLayout()); inchCmButtons.add("North", cmToInchButton);inchCmButtons.add("South", inchToCmButton);inchCmPanel.add(cmText);inchCmPanel.add(cmLabel);inchCmPanel.add(inchCmButtons);inchCmPanel.add(inchText);inchCmPanel.add(inchLabel);
![Page 56: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/56.jpg)
Practical Work
![Page 57: MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649d935503460f94a79e0e/html5/thumbnails/57.jpg)
import javax.swing.*;import java.awt.*;import java.awt.event.*;
public class ChangingFace extends JFrame implements ActionListener{ private boolean isHappy = true; private JButton happyButton = new JButton("Smile"); private JButton sadButton = new JButton("Frown");
public ChangingFace() // code goes here
public void paint(Graphics g) // code goes here
public void actionPerformed (ActionEvent e) // code goes here}
Face now has three moods
declare an extra Jbutton
Add extra button and give it a listener
Check mood and paint frown, smile or thinkProcess three button clicks
So try changing to an int type (1 = happy, 2 = sad, 3 = frown?)