![]() | ![]() | ![]() | 4.7 Week 7 - Java Object Terminology 3 - awt & swing |
awt & swing int but the method
requires a double.
/* Louis Taber Pima Community College */
/* Subsumption example Feb 24, 2003 */
class Subsumption
{
public Subsumption(int a, double b)
{
System.out.println( " int a, double b ");
}
public Subsumption(double a, int b)
{
System.out.println( " double a, int b ");
}
public Subsumption(double a, double b, double c)
{
System.out.println( " double a, double b, double c ");
}
public static void main(String [] args)
{
Subsumption a = new Subsumption(1,2.0);
Subsumption b = new Subsumption(2.0,1);
Subsumption c = new Subsumption((double)1,2);
// Subsumption c = new Subsumption(1,2);
// Subsumption.java:21: reference to Subsumption is ambiguous,
// both method
// Subsumption(int,double) in Subsumption
// and method
// Subsumption(double,int) in Subsumption match
Subsumption d = new Subsumption(1,2,3);
}
}
Note: The compiler complained when it could not find a specific method to call. I have commented out the call and edited in the error message from the compiler.
And the output of the above program:
int a, double b double a, int b double a, int b double a, double b, double c
new.
swing is in javax.swing
swing components use the awt (Advanced Windowing Toolkit)
parts and pieces.
swing components are prefixed with a "J".
Illuiminator.
Implement the methods getName(), getPower(), and
getIllumination()
UsesElectricity with the method
getPower.
implement the UsesElectricity interface in the
LED, and Incandescent classes.
main() program will need to define an array
or linked list with of type Illuminator. Place the
following objects and data in the array or
on the linked list.
Illuminator in classes LED,
Incandescent, and Tritium.
UsesElectricity, power = Voltage * Current.
| Class | Name | Efficiency | Voltage | Current | Power |
| LED | Red | .17 | 3.2v | .01A | |
| LED | Green | .21 | 3.6v | .01A | |
| Incandescent | Standard | .03 | 120v | .80A | |
| Incandescent | Halogen | .04 | 120v | .80A | |
| Tritium | Tritium | .05 | .05W | ||
javax.swing
/* Louis Taber, PCC 2/25/2003 */
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.*;
public class Window
{
static JFrame aWindow = new JFrame( " Title - One");
public static void main(String[] args)
{
aWindow.setBounds( 50, 100, 400, 150);
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aWindow.getContentPane().setBackground(Color.red);
aWindow.setVisible(true);
WindowClose close = new WindowClose(aWindow);
aWindow.addWindowListener( close );
}
}
and
/* Louis Taber, PCC 2/25/2003 */
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Component;
import java.awt.geom.Point2D;
import java.awt.*;
public class WindowClose implements WindowListener
{
JFrame aWindow;
Point pt = null;
WindowClose(JFrame aWindow)
{
this.aWindow = aWindow;
}
public void windowClosing(WindowEvent e)
{System.out.println("windowClosing");}
public void windowClosed(WindowEvent e)
{System.out.println("windowClosed"); }
public void windowOpened(WindowEvent e)
{System.out.println("windowOpened"); }
public void windowIconified(WindowEvent e)
{System.out.println("windowIconified");}
public void windowDeiconified(WindowEvent e)
{System.out.println("windowDeiconified");}
public void windowActivated(WindowEvent e)
{
System.out.println("windowActivated");
if( pt == null ) pt = new Point();
pt = aWindow.getLocation();
Point pt = new Point( aWindow.getLocation());
System.out.println( pt );
aWindow.setVisible(true);
}
public void windowDeactivated(WindowEvent e)
{ System.out.println("windowDeactivated");}
}
![]() | ![]() | ![]() | 4.7 Week 7 - Java Object Terminology 3 - awt & swing |