Malprogramm mit java
import java.applet.*;
import java.awt.*;
import java.awt.
event.*;
public class painter extends Applet implements MouseListener,
ActionListener, MouseMotionListener
{
int X = 0;
int Y = 0;
int prevX = 0;
int prevY = 0;
int farbe = 0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
setBackground(Color.white);
Button delB = new Button("Löschen");
Button gelbB = new Button("Gelb");
Button blauB = new Button("Blau");
Button rotB = new Button("Rot");
Button grünB = new Button("Grün");
Button schwarzB = new Button("Schwarz");
Button radiererB = new Button("Radierer");
Button kleinerB = new Button("Kleiner Kreis");
Button halbB = new Button("Halb Kreis");
Button quadratB = new Button("Quadrat");
Button clearB = new Button("Clear Rect");
Button großerB = new Button("Großer Kreis");
Button schwquadratB = new Button("Schwarzes Quadrat");
this.add(delB);
delB.addActionListener(this);
this.add(gelbB);
gelbB.
addActionListener(this);
this.add(blauB);
blauB.addActionListener(this);
this.add(rotB);
rotB.addActionListener(this);
this.add(grünB);
grünB.
addActionListener(this);
this.add(schwarzB);
schwarzB.addActionListener(this);
this.add(radiererB);
radiererB.addActionListener(this);
this.add(kleinerB);
kleinerB.
addActionListener(this);
this.add(halbB);
halbB.addActionListener(this);
this.add(quadratB);
quadratB.addActionListener(this);
this.add(clearB);
clearB.
addActionListener(this);
this.add(großerB);
großerB.addActionListener(this);
this.add(schwquadratB);
schwquadratB.addActionListener(this);
}
public void mousePressed(MouseEvent e)
{
prevX = e.getX();
prevY = e.
getY();
}
public void mouseDragged(MouseEvent e)
{
X = e.getX();
Y = e.getY();
Graphics g = getGraphics();
if (farbe == 1) {g.setColor(Color.yellow);}
if (farbe == 2) {g.setColor(Color.
blue);}
if (farbe == 3) {g.setColor(Color.red);}
if (farbe == 4) {g.setColor(Color.green);}
if (farbe == 5) {g.setColor(Color.
black);}
if (farbe == 6) {g.setColor(Color.white);}
if (farbe == 7) {g.setColor(Color.black);}
g.drawLine(X, Y, prevX, prevY);
prevX = X;
prevY = Y;
}
public void actionPerformed(ActionEvent e)
{
String Klick = e.
getActionCommand();
Graphics g = getGraphics();
if(Klick == "Löschen") {repaint(); farbe = 0;}
if(Klick == "Gelb") { farbe = 1;}
if(Klick == "Blau") { farbe = 2;}
if(Klick == "Rot") { farbe = 3;}
if(Klick == "Grün") { farbe = 4;}
if(Klick == "Schwarz") { farbe = 5;}
if(Klick == "Radierer") { farbe = 6;}
if(Klick == "Kleiner Kreis") { g.drawOval(40, 40, 40, 40);}
if(Klick == "Halb Kreis") {g.drawArc(300, 150, 150, 150, 150, 150);}
if(Klick == "Quadrat") {g.drawRect(100, 200, 100, 100);}
if(Klick == "Clear Rect") {g.clearRect(100, 100, 100,100);}
if(Klick == "Großer Kreis") {g.drawRoundRect(80, 80, 80, 80, 80, 80);}
if(Klick== "Schwarzes Quadrat") {g.
fillRect(450, 150, 150, 150);}
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
Anmerkungen: |
| impressum | datenschutz
© Copyright Artikelpedia.com