das_pseudonym
Little Overclocker
|
He leute ich habn problem: wenn ich die Zeichenfunktion paint Component nenn akutalisiert er zwar die Panels dafür kannman plötzlich (als user) nicht mehr zeichnen, sit vorher aber noch gegangen undich weiß ned was ich flasch gmacht hab. scheib ich aber paint hin wird wenn überhaupt nur das southpanel gezeichnet und der rest ned zeichnen kann man(als user) übrigens auch dann nicht BITTE HELFT MIR! ICH KENN MICH NIMMA AUS! Drawer.java(MainClass) import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Überschrift:</p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/
public class Drawer extends JFrame{
int Xanf = 0, Yanf = 0, Xend = 0, Yend = 0, X1 = 0, Y1 = 0, X2 = 0, Y2 = 0,
Width = 0, Height = 0;
JButton BLinie = new JButton();
JButton BRechteck = new JButton();
JButton BKreis = new JButton();
String CurrentButton = "Linie";
char Typ[];
Rectangle rectangle[] = new Rectangle[100];
Line linien[] = new Line[100];
Kreis circles[] = new Kreis[100];
int t = 0, y = 0, rect = 0, line = 0, circ = 0, Radius = 0;
int lol1=0, lol2=0;
GridLayout gridLayout1 = new GridLayout(7, 1);
GridLayout gridLayout2 = new GridLayout(1, 3);
JLabel XKoo = new JLabel("X:");
JLabel YKoo = new JLabel("Y:");
JLabel Fehler = new JLabel("");
//Den Frame konstruieren
public Drawer() {
super("Mein Painter");
try {
circles[circ] = new Kreis();
rectangle[rect] = new Rectangle();
linien[line] = new Line();
Typ = new char[500];
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setSize(new Dimension(500, 500));
jbInit();
setVisible(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setSize(new Dimension(500, 500));
}
catch (Exception e) {
e.printS*****race();
}
}
public static void main(String[] args) {
Drawer Programm = new Drawer();
}
//Initialisierung der Komponenten
private void jbInit() throws Exception {
East_Panel Panel_East = new East_Panel();
Center_Panel Panel_Center = new Center_Panel();
South_Panel Panel_South = new South_Panel();
Panel_East.setLayout(gridLayout1);
Panel_South.setLayout(gridLayout2);
this.getContentPane().add(Panel_South, BorderLayout.SOUTH);
this.getContentPane().add(Panel_Center, BorderLayout.CENTER);
this.getContentPane().add(Panel_East, BorderLayout.EAST);
}
class East_Panel
extends JPanel
implements ActionListener {
public East_Panel() {
super();
BLinie.setText("Linie");
BRechteck.setText("Rechteck");
BKreis.setText("Kreis");
add(BLinie);
add(BRechteck);
add(BKreis);
BKreis.addActionListener(this);
BLinie.addActionListener(this);
BRechteck.addActionListener(this);
BLinie.setActionCommand("Linie");
BRechteck.setActionCommand("Rechteck");
BKreis.setActionCommand("Kreis");
}
public void actionPerformed(ActionEvent e) {
Xanf = Xend = Yanf = Yend = 0;
CurrentButton = e.getActionCommand();
}
}
class Center_Panel
extends JPanel {
public Center_Panel() {
super();
this.setBackground(Color.WHITE);
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("MOUSEPRESSED!");
Xanf = e.getX();
Yanf = e.getY();
Width = 0;
Height = 0;
Xend = Xanf;
Yend = Yanf;
repaint();
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
System.out.println("MOUSEDRAGGED!");
Xend = e.getX();
Yend = e.getY();
XKoo.setText("X: " + e.getX());
YKoo.setText("Y: " + e.getY());
repaint();
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
XKoo.setText("X: " + e.getX());
YKoo.setText("Y: " + e.getY());
}
});
this.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
System.out.println("MOUSERELEASED!");
if (CurrentButton == "Rechteck") {
rectangle[rect] = new Rectangle();
if (Xanf < Xend) {
if (Yanf < Yend)
rectangle[rect].savePoints(Xanf, Yanf, Width, Height);
else
rectangle[rect].savePoints(Xanf, Yend, Width, Height);
}
else {
if (Yanf < Yend)
rectangle[rect].savePoints(Xend, Yanf, Width, Height);
else
rectangle[rect].savePoints(Xend, Yend, Width, Height);
}
rect++;
Typ[t] = 'R';
t++;
}
if (CurrentButton == "Linie") {
linien[line] = new Line();
linien[line].savePoints(X1, Y1, X2, Y2);
line++;
Typ[t] = 'L';
t++;
}
if (CurrentButton == "Kreis") {
circles[circ] = new Kreis();
circles[circ].savePoints(Xanf, Yanf, Radius);
circ++;
Typ[t] = 'K';
t++;
}
repaint();
}
});
}
}
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, 1280, 1024);
g.setColor(Color.BLACK);
g.drawRect(0,0,20,20);
int r = 0, l = 0, c = 0;
y = 0;
for (int x = 0; x < t; x++) {
if (Typ[x] == 'R') {
rectangle[r].drawFull(g);
r++;
}
if (Typ[x] == 'L') {
linien[l].drawFull(g);
l++;
}
if (Typ[x] == 'K') {
circles[c].drawFull(g);
c++;
}
}
if (CurrentButton == "Rechteck") {
rectangle[0].drawKon(g, Xanf, Xend, Yanf, Yend);
if (Xanf < Xend)
Width = Xend - Xanf;
else
Width = Xanf - Xend;
if (Yanf < Yend)
Height = Yend - Yanf;
else
Height = Yanf - Yend;
}
if (CurrentButton == "Linie") {
linien[0].drawKon(g, Xanf, Xend, Yanf, Yend);
X1 = Xanf;
X2 = Xend;
Y1 = Yanf;
Y2 = Yend;
}
if (CurrentButton == "Kreis") {
lol1=0;
lol2=0;
if(Xanf>Xend)
lol1=Xanf-Xend;
else
lol1=Xend-Xanf;
if(Yanf>Yend)
lol2=Yanf-Yend;
else
lol2=Yend-Yanf;
if(lol1>lol2)
circles[0].drawKon(g, Xanf, Yanf, lol1);
else
circles[0].drawKon(g, Xanf, Yanf, lol2);
}
}
class South_Panel extends JPanel {
public South_Panel() {
this.add(XKoo, null);
this.add(YKoo, null);
this.add(Fehler, null);
}
}
}
Kreis.java import java.awt.*;
import javax.swing.*;
/**
* <p>Überschrift: </p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/
public class Kreis extends Geo {
int points[]=new int[3];
public Kreis() {
}
public void drawKon(Graphics g, int X, int Y, int Radius)
{
g.drawOval(X-Radius, Y-Radius, Radius*2, Radius*2);
}
public void drawFull(Graphics g)
{
g.fillOval(points[0]-points[2], points[1]-points[2], points[2]*2, points[2]*2);
}
public void savePoints(int X, int Y, int Radius)
{
points[0]=X;
points[1]=Y;
points[2]=Radius;
}
}
Geo.java import javax.swing.*;
import java.awt.*;
/**
* <p>Überschrift: </p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/
abstract class Geo {
public Geo()
{}
public void drawKon()
{}
public void drawFull()
{}
public void savePoints()
{}
}
Rectangle: import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane.*;
/**
* <p>Überschrift: </p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/
public class Rectangle extends Geo {
int points[]=new int[4];
public Rectangle()
{}
public void drawKon(Graphics g, int Xanf, int Xend, int Yanf, int Yend)
{
if (Xend < Xanf) {
if (Yend < Yanf) {
g.drawRect(Xend, Yend, Xanf - Xend, Yanf - Yend);
}
else {
g.drawRect(Xend, Yanf, Xanf - Xend, Yend - Yanf);
}
}
if (Xanf < Xend) {
if (Yend < Yanf) {
g.drawRect(Xanf, Yend, Xend - Xanf, Yanf - Yend);
}
else {
g.drawRect(Xanf, Yanf, Xend - Xanf, Yend - Yanf);
}
}
}
public void drawFull(Graphics g)
{
g.fillRect(points[0], points[1], points[2], points[3]);
}
public void savePoints(int X, int Y, int Width, int Height)
{
points[0] = X;
points[1] = Y;
points[2] = Width;
points[3] = Height;
}
}
Line.java import java.awt.*;
/**
* <p>Überschrift: </p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/
public class Line extends Geo {
int points[]=new int[4];
public Line() {
}
public void drawKon(Graphics g, int Xanf, int Xend, int Yanf, int Yend)
{
System.out.println("ZEIHCNEN?!");
g.drawLine(Xanf, Yanf, Xend, Yend);
}
public void drawFull(Graphics g)
{
g.drawLine(points[0], points[1], points[2], points[3]);
}
public void savePoints(int X1, int Y1, int X2, int Y2)
{
points[0]=X1;
points[1]=Y1;
points[2]=X2;
points[3]=Y2;
}
}
MfG tia pseudo
|