Ich versuche, ein Diagramm anzuzeigen, sobald die Datei mit der Repaint-Methode ausgewählt wurde, Es liefert mir keine Fehler, aber es ist etwas, was ich falsch mache, dass es nicht die Grafik anzeigt, bin ich neu in der Malmethode, also denke ich, das ist warum es nicht funktioniert.JPanel Paint-Methode
Code:
private final JPanel buttonPanel = new JPanel();
private final JTextArea listArea = new JTextArea();
//private final JTextArea graphArea = new JTextArea();
Im Folgenden wird die JPanel Ich versuche, die Ausgabe Grafik:
private final JPanel graphArea = new JPanel();
private final JButton read = new PosJButton("Read", 0);
private final JButton breadth = new PosJButton("Breadth", 0);
private final JButton depth = new PosJButton("Depth", 0);
Meine Klasse für Neuanstrich der Platte:
private class graphArea extends JPanel {
public graphArea() {
graphArea.setPreferredSize(new Dimension(255,255));
}
@Override
public void paintComponent(Graphics g) {
}
}
//method creating a new gui
public static void makeAndShowGUI() {
graphGUI gGUI = new graphGUI();
gGUI.showGUI();
}
//setting items for gui
yout);
listArea.setRows(1);
);
contentPane.add(buttonPanel);
contentPane.add(graphArea);
newStation.addStation(name, posx, posy);
System.out.println("Station test: " + name + " " + posx + " " + posy);
}
else if(type.equals("Connection:")){
String statA = sc.next();
String statB = sc.next();
double dist = sc.nextDouble();
newStation.addConnection(statA, statB, dist);
System.out.println("Connection test: " + statA + " " + statB + " " + dist);
}
}
Hier ist, wo Ich versuche, das jpanel graphArea neu zu streichen:
graphArea.repaint();
}catch(FileNotFoundException ex){
JOptionPane.showMessageDialog(null, "invalid file format", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
});
Wie würde ich das tun? – codingmachine
@codingmachine, lesen Sie den Abschnitt aus dem Swing-Tutorial zu [Custom Painting] (http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html) für ein funktionierendes Beispiel. – camickr