Java Intro Overview
Java Intro Overview
Understand:
int findArea ( )
{
return height * width ;
}
}
Driver or Test program
saved in file
TestRectangle.java
} say:
r’s findArea
public class Rectangle
{
public static void main ( String [ ] args )
{
Rectangle r ;
}
}
Defining & Executing
a window-like object
Import Java
import javax.swing.* ; class libraries
import java.awt.* ; to be used
import java.awt.event.* ;
X is a JFrame
} ...and maybe more
currently...
just a shell
import javax.swing.* ;
import java.awt.* ; class X
import java.awt.event.* ;
file X.java
inputs multiply
Plan of Attack for calculator object
Structure Java
3. JPanel
hello
button
4. JTextField JButton
JFrame
Panel
Declare panel p
public Y()
{
p = new JPanel() ;
Create panel p
this.getContentPane().add(p) ;
Add p to pane
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Fields & Buttons
public class Y extends JFrame implements ActionListener
{
JPanel p;
JTextField n1, n2, n3;
JButton b1,b2; declare fields & buttons
public Y()
{
p = new JPanel();
this.getContentPane().add(p);
}
import javax.swing.*;
import java.awt.*; says class has events
Events
import java.awt.event.*;
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
b1.addActionListener(this);
b2.addActionListener(this);
}
TextPad JPanels
Classes JPanel’s add method
Objects this notation
Methods ActionEvent
Instances of objects ActionEvent’e getSource() method
JFrame’s setSize method
Event-driven programming
JFrame’s setVisible method
Asynchronous import statements
Inheriting properties & methods Multiple instances
extend class Program structure
Constructors
Method signature
JFrames
GUI components Color objects
RGB representation
JTextFields
JPanel’s setBackground ( c) method
JButtons
JLabels dos IO – MyInput.readString ( )