Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Swing - Repaint() not working
    text
    copied!<p>Following is my code. The GUI is not clearing itself on the mouse click event even though the action listener function is being called-</p> <pre><code>package GUI; import java.awt.Color; import java.awt.Event; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseListener; import javax.swing.*; import ospackage.tablefunctions; public class GUI_new extends JPanel implements ActionListener{ Graphics g1; JButton buttonNext = new JButton(); int L=0; public void display() { final JFrame f=new JFrame("Rectangle"); f.setContentPane(new GUI_new()); f.setSize(1000,1000); f.setVisible(true); f.getContentPane().setBackground(Color.BLACK); f.setLayout(null); f.add(buttonNext); buttonNext.setBounds(900,30, 200, 200); buttonNext.setVisible(true); buttonNext.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub //printBlocks(g, 100); //buttonNext.revalidate(); removeAll(); revalidate(); //f.repaint(); //System.out.println("called repaint"); repaint(); System.out.println("called"); } }); } tablefunctions io = new tablefunctions(); public void paint(final Graphics g) { super.paint(g); printBlocks(g, 0); } public void printBlocks(Graphics g , int offset ) { int i=0,j=0,l=offset; for(i=20;i&lt;620;i=i+60) { for(j=20;j&lt;820;j=j+80) { String temp=Integer.toString(l); if(!io.retrieveData("FAT","address" , 2, temp).equals("free")) g.setColor(Color.RED); else g.setColor(Color.GREEN); g.drawRect(j, i, 60, 30); g.fillRect(j, i, 60, 30); g.drawString("Cluster" + l,j , i-5 ); l++; } } } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub // e.getSource().equals() } public static void main(String[] args) { GUI_new gn = new GUI_new(); gn.display(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload