Tuesday, May 1, 2007

WinDerivedClassCatTest

import javax.swing.*;
import java.awt.*;

public class WinDerivedClassCatTest extends JFrame{

//ds
int row = 10, col = 10;
String output = "";

public static void main(String[] args){
WinDerivedClassCatTest cattest = new WinDerivedClassCatTest();
cattest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cattest.setBounds(150,150,400,300);
cattest.setVisible(true);
}

public WinDerivedClassCatTest(){
super("Inheritance Demo For Cats");

Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
pane.setBackground(new Color(250,100,50));

//add text area
JTextArea textarea = new JTextArea(row,col);
//pane.add(textarea);

DerivedClass aCat = new DerivedClass("Toger","Tiger");
Cat bCat = new Cat("Meeeiaow");

//output here

output += aCat+"\n";
output += bCat+"\n";

//display here
textarea.setText(output);
pane.add(textarea,BorderLayout.NORTH);
}
}

Cat

public class Cat extends SuperClass{

//name and breed
private String name;
private String breed;

public Cat(String animalName){
super("Cat");
name = animalName;
breed = "Unknown";
}

//animal constructor
public Cat(String animalName,String animalBreed){
super("Cat");
name = animalName;
breed = animalBreed;
}

//convert to String
public String toString(){
return super.toString() + "\n" + name + "is a" + breed + "type of cat.\n";
}
}

DerivedClass

public class DerivedClass extends SuperClass{
//name and breed
private String name;
private String breed;

public DerivedClass(String animalName){
super("Dog");
name = animalName;
breed = "Unknown";
}

//animal constructor
public DerivedClass(String animalName,String animalBreed){
super("Dog");
name = animalName;
breed = animalBreed;
}

//convert to string
public String toString(){
return super.toString() +"\n"+name+"is a"+breed+"type of dog.\n";
}
}

SuperClass

public class SuperClass{
//animal type
private String type;

public SuperClass(String animalType){
type = new String( animalType );
}

//conversion to string
public String toString(){
return "This is a type of" + type + ".";
}
}

SysFontInfo

import java.awt.*;
import java.awt.GraphicsEnvironment;
import java.awt.Dimension;
import javax.swing.*;
import java.io.*;
//import j2packs.BottomPanel;
//import j2packs.TopPanel;

public class SysFontInfo extends JFrame {

//cdm
String output ="", topTitle ="";
int count, txtrow, txtcol;

public static void main(String[] args){
SysFontInfo fontsavailable = new SysFontInfo();
fontsavailable.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
fontsavailable.setSize(400,300);
fontsavailable.setVisible(true);
}

public SysFontInfo(){

super("Fonts on this PlatForm");
displayFonts();
}

protected void displayFonts(){

Container pane = getContentPane();
pane.setBackground(Color.blue);
pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

JTextArea outputArea = new JTextArea(txtrow,txtcol);

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension winSize = toolkit.getScreenSize();

output += "This computer has the following specs:\n";
output += "Screen resolution: " + toolkit.getScreenResolution();
output += "dots per inch.\n";
output += "Screen size: " + winSize.width + " x ";
output += winSize.height + "pixels\n";

GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontnames = e.getAvailableFontFamilyNames();

output += "Font available on this platform:\n";
for(count = 0;count < fontnames.length;count++){
output += "" + (count+1) + "" + fontnames[count] + "\n";
}

//display
outputArea.setText(output);
outputArea.setFont(new Font("Tahoma",Font.PLAIN,14));
outputArea.setEditable(false);
pane.add(outputArea);

JScrollPane scrollpane = new JScrollPane(outputArea);
pane.add(scrollpane);

//add top and bottom panel
//topTitle = "SYSTEM INFORMATION";
// pane.add(new TopPanel(topTitle), BorderLayout.NORTH);
// pane.add(new BottomPanel(), BorderLayout.SOUTH);
}
}