Dimitris Kerkezos
Dimitris Kerkezos

Reputation: 23

JFrame Update issue

I want to appear two differenet Frames with different results in eachone. My code is :

JFrame frame = new JFrame("Before the outage in Maximization");
MyCanvas canvas = new MyCanvas(initials.vaccesspoint,initials.vTerminal);
frame.setSize(initials.frameSize, initials.frameSize);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(canvas);
frame.setVisible(true);
Graphics graph = canvas.getGraphics();
canvas.paintComponent(graph);

After this, I write some code so as to change the index of the last frame and then i run again this :

JFrame frame2 = new JFrame("Before the outage in Maximization");
MyCanvas canvas2 = new MyCanvas(initials.vaccesspoint,initials.vTerminal);
frame2.setSize(initials.frameSize, initials.frameSize);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.add(canvas2);
frame2.setVisible(true);
Graphics graph2 = canvas2.getGraphics();
canvas2.paintComponent(graph2);

Then they appear both of the frames but they have the same information. this is wrong. Any help please?

Upvotes: 0

Views: 119

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347184

These two lines are identical

MyCanvas canvas = new MyCanvas(initials.vaccesspoint,initials.vTerminal);
MyCanvas canvas2 = new MyCanvas(initials.vaccesspoint,initials.vTerminal);

So we have to assume that somewhere, the data s different..

And these lines are not required

Graphics graph = canvas.getGraphics();
canvas.paintComponent(graph);

Graphics graph2 = canvas2.getGraphics();
canvas2.paintComponent(graph2);

In fact, I'd say they're are a bad idea. You don't control the paint process, Swing does.

Upvotes: 2

Related Questions