Jpanel nicht immer zeichnetJava

Java-Forum
Anonymous
 Jpanel nicht immer zeichnet

Post by Anonymous »

Ich habe also ein Programm, das einige Werte aus einer Datei nimmt und sie speichert, die berechnet werden und dann auf dem Bildschirm gezeichnet werden sollen. Der Teil, der die Werte nimmt und sie berechnet, funktioniert funktioniert, aber mein JPanel malt es nicht immer, es funktioniert manchmal, aber sobald ich die Registerkarte verändert habe, weiß ich nicht, warum. Hier sind meine Codes: < /p>
Simulator: < /p>

Code: Select all

package IDK;

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

import window.*;

public class simulator {

static File file;
static HashMap  fileCont = new HashMap  ();
static Rectangle viewBox = new Rectangle ();
static int [] camInfo = new int [3];
static int keyCode;

public static void start () {

camInfo [0] = 12;
camInfo [1] = 0;
camInfo [2] = 0;

int partNum = 0;
String [] partSeg;
fileAccessor ("test", "read");

while ((partSeg = fileCont.get (partNum).split (":")) [0].equals ("cP") == false) {

partNum ++;
}

part [] parts = new part [partNum]; //Part is a custom variable that is used for the calculations using the .step () function.

for (int i = 0; i < partNum; i ++) {

partSeg = fileCont.get (i).split (":");
parts [i] = new part (partSeg [0], Integer.valueOf (partSeg [1]), Integer.valueOf (partSeg [2]), Integer.valueOf (partSeg [3]), Integer.valueOf (partSeg [4]));
}

fileCont.clear ();

for (int i = 0; i < partNum; i ++) {

parts [i].step ();
fileCont.put (i, parts [i].type + ":" + parts [i].x + ":" + parts [i].y + ":" + parts [i].xVel + ":" + parts [i].yVel);
}

int inViewNum = 0;
viewBox = new Rectangle (camInfo [1], camInfo [2], (int) camInfo [1] + frame.f.getWidth () / 100 * camInfo [0], (int) camInfo [1] + frame.f.getHeight () / 100 * camInfo [0]);

for (int i = 0; i < partNum; i ++) {

if (parts [i].x >= viewBox.x & parts [i].y >= viewBox.y & parts [i].x 
Frame: < /p>
package window;

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

public class frame {

public static JFrame f = new JFrame ("frame");
public static JPanel p = new panel ();

public static void createWindow () {

f.add (p);
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
f.setMinimumSize (new Dimension (800, 500));
f.setLocationRelativeTo (null);
f.setVisible (true);
}
}
< /code>
Panel: < /p>
package window;

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

public class panel extends JPanel {

public static HashMap  graphParts = new HashMap  ();
static int partNum = 0;

public void paintComponent (Graphics g) {

super.paintComponent (g);

while (graphParts.get (partNum) != null) {

String [] graphSeg = graphParts.get (partNum).split (":");
g.setColor (new Color (Integer.valueOf (graphSeg [5]), Integer.valueOf (graphSeg [6]), Integer.valueOf (graphSeg [7])));

if (graphSeg [0].equals ("oval")) {

g.fillOval (Integer.valueOf (graphSeg [1]), Integer.valueOf (graphSeg [2]), Integer.valueOf (graphSeg [3]), Integer.valueOf (graphSeg [4]));
} else if (graphSeg [0].equals ("rect")) {

g.fillRect (Integer.valueOf (graphSeg [1]), Integer.valueOf (graphSeg [2]), Integer.valueOf (graphSeg [3]), Integer.valueOf (graphSeg [4]));
}

partNum ++;
}
}
}
< /code>
Teil: < /p>
package IDK;

public class part {

int x, y, xVel, yVel, state;
String type;

public part () {

}

public part (String interfaceType, int interfaceX, int interfaceY, int interfaceXVel, int interfaceYVel) {

type = interfaceType;
x = interfaceX;
y = interfaceY;
xVel = interfaceXVel;
yVel = interfaceYVel;
}

void step () {

switch (type) {

case "p+":
x += xVel;
y += yVel;
break;

case "n0":
x += xVel;
y += yVel;
break;

case "e-":
x += xVel;
y += yVel;
break;

case "Y":
x += xVel;
y += yVel;
break;
}
}
}
< /code>
Test (die Datei mit den Werten): < /p>
p+:0:0:0:0
n0:0:0:0:0
e-:0:0:0:0
Y:0:0:0:0
cP:0:0
Hilfe wird geschätzt.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post