Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does using ActionListener break my Swing Applet?
    primarykey
    data
    text
    <p>I have an application working in Java Swing, but can't seem to convert to an Applet. Basically there are four buttons displayed on the Applet, and I want one of them to clear the screen and then draw a new interface (I'm going to add stuff for the other buttons, of course, but I got stuck here).</p> <pre class="lang-java prettyprint-override"><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.JApplet; //import swing applet interface import java.util.Hashtable; public class TopMenu extends JApplet{ private JPanel panel = new JPanel(); public void init(){ mainMenu(); } public void mainMenu() { // create buttons panel.setLayout(new GridLayout(2, 2)); JButton collectButton = new JButton("Collect data"); JButton uploadButton = new JButton("Upload"); JButton downloadButton = new JButton("Download"); JButton exploreButton = new JButton("Explore data"); panel.add(collectButton); panel.add(uploadButton); panel.add(downloadButton); panel.add(exploreButton); collectButton.addActionListener(new ActionListener( ) { public void actionPerformed(ActionEvent e) { int numberGFish = 400; //panel.removeAll(); //panel.add(new JLabel("Just to test"), BorderLayout.CENTER); //panel.revalidate(); //panel.repaint(); } }); setContentPane(panel); } } </code></pre> <p>All the code works totally fine until I add the ActionListener, and then the whole thing just goes blank. It compiles okay, but when I test it on my server not even the first menu comes up, it's just a blank panel. I've tried putting loads of really banal things in the ActionListener bit to make sure it's not a problem with them, but as you can see even just declaring a number in there doesn't work.</p> <p>Originally I actually had the Listener bit call on another method which then did everything else, and that didn't work either, I scrapped that because I thought perhaps that was the problem.</p> <p>I'm sure this is so simple but I've sunk many hours into it now and I've really just run out of ideas of things to test. And advice gratefully appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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