Hi, I have a JFrame application that holds 4 JInternal Frame
On one of the JInternalFrame, i do some drawing, I basically move the mouse around and when I click on it, it draws a little oval (of radius 4) on the JInternalframe. When I click on another JInternalFrame, anythign I have drawn dissapears (except for the last pixel that I've drawn)
An example is shown here:
I've added the notes on the window so we can understand better In the top window, the focus is set to the board's window and there is a drawing there drawn with the mouse. Then, on the bottom window, the focus is set to the slideshow window and everything that is drawn on the board's window has dissapeared
Can anyone tell me how I can fix this problem? When my first JInternalFrame loses its focus, I don't want it to erase all the dots and lines I have drawn.
This is the current code I have for a panel inside my JInternalFrame that takes care of drawing the coordinates i click with the mouse:
(Note: the code below is called from my JInternalFrame. Inside the JInternalFrame, i create an instance of BoardServer which is a JPanel that I include in my JinternalFrame.
On one of the JInternalFrame, i do some drawing, I basically move the mouse around and when I click on it, it draws a little oval (of radius 4) on the JInternalframe. When I click on another JInternalFrame, anythign I have drawn dissapears (except for the last pixel that I've drawn)
An example is shown here:
I've added the notes on the window so we can understand better In the top window, the focus is set to the board's window and there is a drawing there drawn with the mouse. Then, on the bottom window, the focus is set to the slideshow window and everything that is drawn on the board's window has dissapeared
Can anyone tell me how I can fix this problem? When my first JInternalFrame loses its focus, I don't want it to erase all the dots and lines I have drawn.
This is the current code I have for a panel inside my JInternalFrame that takes care of drawing the coordinates i click with the mouse:
(Note: the code below is called from my JInternalFrame. Inside the JInternalFrame, i create an instance of BoardServer which is a JPanel that I include in my JinternalFrame.
Code:
// Class BoardServer
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.swing.event.MouseInputAdapter;
public class BoardServer extends JPanel
{
private int x1, y1, x2 = -10, y2 = -10;
int flag;
int pensize = 4;
int colorcode = 1;
public BoardServer()
{
addMouseMotionListener(
new MouseInputAdapter()
{
public void mouseDragged( MouseEvent event )
{
x2 = event.getX();
y2 = event.getY();
displayCoordinates(x2, y2);
flag = colorcode;
}
} // end MouseInputAdapter
); // end addMouseMotionListener
setSize(500,500);
setVisible(true);
}
public void displayCoordinates(int x, int y)
{
x = x2;
y = y2;
paintImmediately(x,y,pensize,pensize);
}
public void paintComponent(Graphics g)
{
Dimension size = getSize();
int x = 0;
int y = 0;
pensize = 4;
g.setColor(Color.black);
if ( colorcode == 2 ) { g.setColor(Color.blue); }
if ( colorcode == 3 ) { g.setColor(Color.green); }
if ( colorcode == 4 ) { g.setColor(Color.red); }
if ( colorcode == 5 ) { g.setColor(Color.yellow); }
if ( colorcode == 6 ) { g.setColor(Color.white); }
if ( colorcode == 7 ) { g.setColor(Color.white); pensize = 40; }
}
public void paint(Graphics g)
{
pensize = 4;
g.setColor(Color.black);
if ( colorcode == 2 ) { g.setColor(Color.blue); }
if ( colorcode == 3 ) { g.setColor(Color.green); }
if ( colorcode == 4 ) { g.setColor(Color.red); }
if ( colorcode == 5 ) { g.setColor(Color.yellow); }
if ( colorcode == 6 ) { g.setColor(Color.white); }
if ( colorcode == 7 ) { g.setColor(Color.white); pensize = 40; }
super.paintComponent(g);
g.fillRect(x2,y2,pensize+2,pensize+2);
}
public void setPenColor(int code)
{
colorcode = code;
}
public Dimension getPreferredSize()
{
return new Dimension(430, 430);
}
public void eraseBoard()
{
repaint();
x1 = -100;
y1 = -100;
x2 = -100;
y2 = -100;
}
}