JAVA AWT Example to learn
package com.mission;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.plaf.metal.MetalBorders.TextFieldBorder;
public class AWTDemo extends Frame implements WindowListener,MouseListener,MouseMotionListener,KeyListener{
public AWTDemo()
{
addWindowListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
setTitle("My Application");
setSize(400, 400);
setLayout(new FlowLayout());
setVisible(true);
setBackground(Color.blue);
Button b1=new Button("Click e");
Button b2=new Button("Clcik me ");
add(b1);
add(b2);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {
setMinimumSize(100);
}
private void setMinimumSize(int i) {
}
public void windowOpened(WindowEvent e) {
}
public void mouseClicked(MouseEvent e) {
setBackground(Color.pink);
}
public void mouseEntered(MouseEvent e) {
setBackground(Color.yellow);
}
public void mouseExited(MouseEvent e) {
setBackground(Color.orange);
}
public void mousePressed(MouseEvent e) {
setBackground(Color.green);
}
public void mouseReleased(MouseEvent e) {
setBackground(Color.MAGENTA);
}
public void mouseDragged(MouseEvent arg0) {
setForeground(Color.darkGray);
}
public void mouseMoved(MouseEvent arg0) {
setCursor(HAND_CURSOR);
}
public static void main(String args[])
{
AWTDemo f=new AWTDemo();
}
public void keyPressed(KeyEvent arg0) {
setBackground(Color.white);
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
setBackground(Color.pink);
}
}
Comments
Post a Comment