**When I try to change location of any component such as Button
Label
TextField
some part of my shapes becomes invisible.When I delete the code where I set location to component(in this case it is TextField
) shapes becomes to normal. **
public class Line {
public static void main(String[] args) {
JFrame frame = new JFrame("JFrame Example");
frame.setSize(1366, 768);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.setVisible(true);
JButton button=new JButton("Show lines");
frame.add(button);
button.setBounds(60, 400, 220, 30);
button.setVisible(true);
JTextField txtf=new JTextField();
frame.add(txtf);
txtf.setVisible(true);
txtf.setSize(50, 100);
button.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent me) {
button.setVisible(false);
Graphics2D grf= (Graphics2D) frame.getGraphics();
txtf.setVisible(false);
txtf.setText("APPLE");
txtf.setLocation(600, 600);
txtf.setVisible(true);
grf.fillOval(600, 600, 10, 10);
grf.fillOval(190, 600, 10, 10);
grf.fillOval(900, 650, 10, 10);
grf.fillOval(750, 160, 10, 10);
grf.fillOval(600, 400, 10, 10);
grf.fillOval(1139, 266, 10, 10);
grf.drawLine(1144, 271, 605, 405);
grf.drawLine(195, 605, 605, 405);
grf.drawLine(755, 165, 605, 405);
grf.drawLine(755, 165, 1144, 271);
grf.drawLine(905, 655, 1144, 271);
grf.drawLine(905, 655, 605, 405);
grf.drawLine(205, 205, 605, 405);
grf.drawLine(205, 205, 755, 165);
}
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
});
button.setVisible(true);
}
}