import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Drag extends Applet {
private int x=-5,y=-5;
public void init(){
MouseMotionHandler mh=new MouseMotionHandler(this);
addMouseMotionListener(mh);
}
public void paint (Graphics g){
g.fillOval(x,y,3,3);
}
public void update (Graphics g)
{
paint(g);
}
public void setCor(int x1,int y1){
x=x1;
y=y1;
repaint();
}
}
class MouseMotionHandler extends MouseMotionAdapter{
private Drag dragger;
public MouseMotionHandler(Drag d)
{
dragger=d;
}
public void mouseDragged(MouseEvent e)
{
dragger.setCor(e.getX(),e.getY());
}
}
Blogger templates
Thursday, July 16, 2009
WHICH KEY IS DOWN
mport java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Keyboard1 extends Applet implements KeyListener
{
String s;
char c;
public void init(){
addKeyListener(this);
requestFocus();
}
public void keypressed(KeyEvent e)
{
s=e.getKeyText(e.getKeyCode());
showStatus("patithike to :"+s);
}
public void keyReleased(KeyEvent e){
s=e.getKeyText(e.getKeyCode());
showStatus("KEY IS :"+s);
}
public void keyTyped(KeyEvent e){
c=e.getKeyChar();
s=String.valueOf(c);
showStatus("KEY IS :"+s);
}
}
import java.awt.*;
import java.awt.event.*;
public class Keyboard1 extends Applet implements KeyListener
{
String s;
char c;
public void init(){
addKeyListener(this);
requestFocus();
}
public void keypressed(KeyEvent e)
{
s=e.getKeyText(e.getKeyCode());
showStatus("patithike to :"+s);
}
public void keyReleased(KeyEvent e){
s=e.getKeyText(e.getKeyCode());
showStatus("KEY IS :"+s);
}
public void keyTyped(KeyEvent e){
c=e.getKeyChar();
s=String.valueOf(c);
showStatus("KEY IS :"+s);
}
}
Mouse AREA 2
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Mouse2 extends Applet implements
MouseListener,MouseMotionListener {
private String s="";
private String s1="";
private int x,y;
public void init(){
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g) {
g.drawString(s+ " "+"("+x+","+y+")",x,y);
}
public void setState(String s1,int x1,int y1){
s=s1;
x=x1;
y=y1;
repaint();
}
public void mouseClicked(MouseEvent e){
s1="";
if(e.isMetaDown())
s1+="dexio pathma";
else if(e.isAltDown())
s1+="mesaio pathma";
else s1="aristero pathma";
setState(s1,e.getX(),e.getY());
}
public void mousePressed(MouseEvent e){
s1="";
if(e.isMetaDown())
s1+="dexio pliktro";
else if(e.isAltDown())
s1+="mesaio pliktro";
else s1="aristero pliktro";
setState("piestike to "+s1,e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e){
setState("apeley8erw8hke to pliktro",e.getX(),e.getY());
}
public void mouseEntered(MouseEvent e){
showStatus("to pontiki einai mesa sthn perioxh tou applet ");
}
public void mouseExited(MouseEvent e){
showStatus("to pontiki einai exw apo thn perioxh tou applet ");
}
public void mouseDragged(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
public void mouseMoved(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
}
import java.awt.*;
import java.awt.event.*;
public class Mouse2 extends Applet implements
MouseListener,MouseMotionListener {
private String s="";
private String s1="";
private int x,y;
public void init(){
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g) {
g.drawString(s+ " "+"("+x+","+y+")",x,y);
}
public void setState(String s1,int x1,int y1){
s=s1;
x=x1;
y=y1;
repaint();
}
public void mouseClicked(MouseEvent e){
s1="";
if(e.isMetaDown())
s1+="dexio pathma";
else if(e.isAltDown())
s1+="mesaio pathma";
else s1="aristero pathma";
setState(s1,e.getX(),e.getY());
}
public void mousePressed(MouseEvent e){
s1="";
if(e.isMetaDown())
s1+="dexio pliktro";
else if(e.isAltDown())
s1+="mesaio pliktro";
else s1="aristero pliktro";
setState("piestike to "+s1,e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e){
setState("apeley8erw8hke to pliktro",e.getX(),e.getY());
}
public void mouseEntered(MouseEvent e){
showStatus("to pontiki einai mesa sthn perioxh tou applet ");
}
public void mouseExited(MouseEvent e){
showStatus("to pontiki einai exw apo thn perioxh tou applet ");
}
public void mouseDragged(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
public void mouseMoved(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
}
MOUSE AREA
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Mouse1 extends Applet implements
MouseListener,MouseMotionListener {
private String s="";
private int x,y;
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g){
g.drawString(s+ " "+"("+x+","+y+")",x,y);
}
public void setState(String s1,int x1,int y1){
s=s1;
x=x1;
y=y1;
repaint();
}
public void mouseClicked(MouseEvent e){
setState("klik",e.getX(),e.getY());
}
public void mousePressed(MouseEvent e){
setState("piestike to pliktro",e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e){
setState("apeley8erw8hke to pliktro",e.getX(),e.getY());
}
public void mouseEntered(MouseEvent e){
showStatus("to pontiki einai mesa sthn perioxh tou applet ");
}
public void mouseExited(MouseEvent e){
showStatus("to pontiki einai exw apo thn perioxh tou applet ");
}
public void mouseDragged(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
public void mouseMoved(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
}
import java.awt.*;
import java.awt.event.*;
public class Mouse1 extends Applet implements
MouseListener,MouseMotionListener {
private String s="";
private int x,y;
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g){
g.drawString(s+ " "+"("+x+","+y+")",x,y);
}
public void setState(String s1,int x1,int y1){
s=s1;
x=x1;
y=y1;
repaint();
}
public void mouseClicked(MouseEvent e){
setState("klik",e.getX(),e.getY());
}
public void mousePressed(MouseEvent e){
setState("piestike to pliktro",e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e){
setState("apeley8erw8hke to pliktro",e.getX(),e.getY());
}
public void mouseEntered(MouseEvent e){
showStatus("to pontiki einai mesa sthn perioxh tou applet ");
}
public void mouseExited(MouseEvent e){
showStatus("to pontiki einai exw apo thn perioxh tou applet ");
}
public void mouseDragged(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
public void mouseMoved(MouseEvent e){
setState("to pontiki suretai",e.getX(),e.getY());
}
}
LIST OF NAMES AND SHOW IN A TEXTFIELD
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class showChoice extends Applet implements
ItemListener{
private Choice names;
private TextField tf;
String s;
public void init()
{
names=new Choice ();
names.add("Giorgos");
names.add("Kwstas");
names.add("Giannis");
names.add("Dimitra");
names.add("Balia");
add(names);
names.addItemListener(this);
tf=new TextField(names.getItem(0),20);
tf.setEditable(false);
add(tf);
}
public void itemStateChanged(ItemEvent e)
{
s=(String) e.getItem();
tf.setText(s);
}
}
import java.awt.*;
import java.awt.event.*;
public class showChoice extends Applet implements
ItemListener{
private Choice names;
private TextField tf;
String s;
public void init()
{
names=new Choice ();
names.add("Giorgos");
names.add("Kwstas");
names.add("Giannis");
names.add("Dimitra");
names.add("Balia");
add(names);
names.addItemListener(this);
tf=new TextField(names.getItem(0),20);
tf.setEditable(false);
add(tf);
}
public void itemStateChanged(ItemEvent e)
{
s=(String) e.getItem();
tf.setText(s);
}
}
SCROLLBAR
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class showScrollbar extends Applet implements
AdjustmentListener {
private Scrollbar scrb;
int i;
TextField tf;
String s;
public void init (){
scrb=new Scrollbar(Scrollbar.HORIZONTAL,20,10,0,255);
add(scrb);
scrb.addAdjustmentListener(this);
tf=new TextField(15);
add(tf);
}
public void adjustmentValueChanged(AdjustmentEvent e){
i=e.getValue();
s=String.valueOf(i);
tf.setText(s);
repaint();
}
}
import java.awt.*;
import java.awt.event.*;
public class showScrollbar extends Applet implements
AdjustmentListener {
private Scrollbar scrb;
int i;
TextField tf;
String s;
public void init (){
scrb=new Scrollbar(Scrollbar.HORIZONTAL,20,10,0,255);
add(scrb);
scrb.addAdjustmentListener(this);
tf=new TextField(15);
add(tf);
}
public void adjustmentValueChanged(AdjustmentEvent e){
i=e.getValue();
s=String.valueOf(i);
tf.setText(s);
repaint();
}
}
2 BUTTONS,WHEN PRESSED CHANGE BACKGROUND
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Buttons1 extends Applet implements ActionListener{
Button bt1, bt2;
String s;
public void init(){
bt1=new Button("Kitrino");
add(bt1);
bt1.addActionListener(this);
bt2=new Button("Kokkino");
add(bt2);
bt2.addActionListener(this);
}
public void paint (Graphics g){
if (s=="Kitrino")
setBackground(Color.yellow);
else if (s=="Kokkino")
setBackground(Color.red);
repaint();
}
public void actionPerfomed(ActionEvent e){
s=e.getActionCommand();
}
}
import java.awt.*;
import java.awt.event.*;
public class Buttons1 extends Applet implements ActionListener{
Button bt1, bt2;
String s;
public void init(){
bt1=new Button("Kitrino");
add(bt1);
bt1.addActionListener(this);
bt2=new Button("Kokkino");
add(bt2);
bt2.addActionListener(this);
}
public void paint (Graphics g){
if (s=="Kitrino")
setBackground(Color.yellow);
else if (s=="Kokkino")
setBackground(Color.red);
repaint();
}
public void actionPerfomed(ActionEvent e){
s=e.getActionCommand();
}
}
Subscribe to:
Posts (Atom)