Results 1 to 2 of 2
- 01-26-2012, 06:27 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Page not refreshing properly within a swing JApplet
Hi, I started java about a week ago and have been trying to make a swing JApplet for a college assignment. The problem I am getting is that when you click a button on the main page, you can see the compnents of the next page rearanging slightly before they are displayed. Is this a problem with my code or does this have to happen?
My JApplet ishere. You will see what I am talking about when you navigate to a page by clicking a button on the menu.
Here is my code for any suggestions. (BTW am I even initialising properly? I'm still new and not quite sure so any help will be much appretiated)
Java Code:import java.awt.*; import java.applet.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; public class main extends JApplet { JPanel screen = new JPanel(); int width; int menuOption = 0; int numberOfOptions = 9; String[] optionNames = { "Local Variables", "Procedures", "Functions", "Loops (for)", "Loops (while)", "Conditional Statements", "Boolean Operators", "Perameter Passing", "Debugging" }; public void init() { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { start(); } }); } catch(Exception e) { System.out.println("Failure to init: "+e); } } public main() { programSwitch(); } public void programSwitch() { screen.removeAll(); switch(menuOption) { case 0: menu(); break; case 1: VariablesPage(); break; case 2: VariablesPage(); break; case 3: VariablesPage(); break; case 4: VariablesPage(); break; case 5: VariablesPage(); break; case 6: VariablesPage(); break; case 7: VariablesPage(); break; case 8: VariablesPage(); break; case 9: VariablesPage(); break; default: menu(); break; } revalidate(); } public void menu() { screen.setLayout(new BorderLayout()); add(screen); JPanel titlePanel = new JPanel(); screen.add(titlePanel, BorderLayout.NORTH); JLabel title = new JLabel("Basic Programming Tutorials"); titlePanel.add(title); JPanel menuPanel = new JPanel(); menuPanel.setLayout(new GridLayout(0,3)); screen.add(menuPanel, BorderLayout.CENTER); JButton[] menuOptions = new JButton[numberOfOptions]; for(int i = 0; i < numberOfOptions; i++) { menuOptions[i] = new JButton(optionNames[i]); menuPanel.add(menuOptions[i]); menuOptions[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleMenuSelect(e.getActionCommand()); } }); } } public void handleMenuSelect(String option) { for( int i = 0; i < numberOfOptions; i++) { if( option == optionNames[i]) { menuOption = i+1; programSwitch(); } } } public void VariablesPage() { width = getSize().width; screen.setLayout(new BorderLayout()); add(screen); JPanel titlePanel = new JPanel(); screen.add(titlePanel, BorderLayout.NORTH); JLabel title = new JLabel(optionNames[menuOption-1]); titlePanel.add(title); JPanel contentPanel = new JPanel(); contentPanel.setLayout(new BorderLayout()); screen.add(contentPanel, BorderLayout.CENTER); JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); contentPanel.add(content, BorderLayout.NORTH); JTextArea thankNote = new JTextArea(); thankNote.setText("This text area will contain information and tutorials about "+optionNames[menuOption-1]); thankNote.setEditable(false); thankNote.setLineWrap(true); c.weightx = 1.0; //c.anchor = GridBagConstraints.NORTHWEST; c.gridx = 1; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10,10,10,10); content.add(thankNote, c); JPanel pageControlPanel = new JPanel(); pageControlPanel.setBackground(Color.black); c.weightx = 1.0; c.gridx = 3; c.gridwidth = 1; c.ipadx = (width/3)-20; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10,10,10,10); content.add(pageControlPanel, c); JButton homeButton = new JButton("HOME"); screen.add(homeButton, BorderLayout.SOUTH); homeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuOption = 0; programSwitch(); } }); } }
- 01-26-2012, 11:26 PM #2
Similar Threads
-
Frames are not woking properly within JApplet
By mitra in forum Java AppletsReplies: 1Last Post: 07-29-2011, 07:02 AM -
populating a list box based on another without refreshing the page
By zahir in forum JavaServer Pages (JSP) and JSTLReplies: 8Last Post: 07-25-2011, 01:09 PM -
japplet - refreshing windows
By Symbiot in forum New To JavaReplies: 6Last Post: 05-29-2010, 06:12 PM -
refreshing the page automatically if the configuration file changes
By anitha2324 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-07-2009, 03:08 PM -
how to stop refreshing page
By cecily in forum New To JavaReplies: 1Last Post: 07-24-2007, 01:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks