Results 1 to 5 of 5
  1. #1
    ryanmk54's Avatar
    ryanmk54 is offline Member
    Join Date
    May 2011
    Posts
    18
    Rep Power
    0

    Post Display diference between window and applet

    I made a JPanel to store all the information in an application. I set this JPanel as the content pane in both the applet version and the standalone version of the program.

    In the application version it displays fine. In the applet version however, I must mouse over the buttons to see them and click on the textfields to see all but the first one. A JLabel is not seen until the text is changed. Also, the background of the JPanels are not what I set them to be. In google chrome the background is white and in firefox it is transparent. I set the background to be gray.

    Could someone please tell me how to fix this?

    One more thing, is there a way to make the applet fit the size of the components like the pack() method in a window?

    Thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ryanmk54 View Post
    In the application version it displays fine. In the applet version however, I must mouse over the buttons to see them and click on the textfields to see all but the first one. A JLabel is not seen until the text is changed. Also, the background of the JPanels are not what I set them to be. In google chrome the background is white and in firefox it is transparent. I set the background to be gray.

    Could someone please tell me how to fix this?
    This isn't a "Java" problem but rather a bug in your code, but without showing us this code how are we supposed to guess what is wrong with it?


    One more thing, is there a way to make the applet fit the size of the components like the pack() method in a window?
    I'm not an applet pro, but I believe that the size of the applet is generally specified by the html code.

  3. #3
    ryanmk54's Avatar
    ryanmk54 is offline Member
    Join Date
    May 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    This isn't a "Java" problem but rather a bug in your code, but without showing us this code how are we supposed to guess what is wrong with it?


    I'm not an applet pro, but I believe that the size of the applet is generally specified by the html code.

    It is a lot of code, so unless you want it in full, I'll just display the initialization.

    initialization
    Java Code:
    public class SimpleCalcMain extends JPanel{
    	JButton button0, button1, button2,  ... more buttons
    	JButton buttonSignChange, buttonDecimal, ... more buttons
    	JButton buttonSqrt, buttonEnter;
    	JTextField xInput, yInput, operatorInput, answerOutput;
    	JLabel statusOutput;
    	BigDecimal x, y, answer;
    	boolean xInputSelected;
    	JPanel buttonsPanel, textFieldsPanel, statusPanel;
    	final Dimension buttonSizePref = new Dimension(55,60);
    
    	public SimpleCalcMain(){
    		setBackground(Color.BLACK);
    		System.out.println("Initializing numbered buttons");
    			button0 = new JButton("0");
    			button0.setPreferredSize(buttonSizePref);
    			button0.addActionListener(new ButtonAction());
    			button1 = new JButton("1");
    			button1.setPreferredSize(buttonSizePref);
    			button1.addActionListener(new ButtonAction());
    			button2 = new JButton("2");
    			button2.setPreferredSize(buttonSizePref);
    			button2.addActionListener(new ButtonAction());
    
                            ...more button initialization
    
    		System.out.println("Initializing variables");
    			x = new BigDecimal(0.00);
    			y = new BigDecimal(0.00);
    			answer = new BigDecimal(0.00);
    			xInputSelected = true;
    		System.out.println("Variables initialized");
    		System.out.println("Initializing textFields");
    			xInput = new JTextField(x.toString(), 8);
    			xInput.setActionCommand("xInput");
    			xInput.addActionListener(new TextFieldAction());
    			xInput.addFocusListener(new FocusAdapter(){
    				public void focusGained(FocusEvent evt){
    					xInputSelected = true;
    				}
    			});
    
                            ... textfield y initialization
    displaying the panels
    Java Code:
    buttonsPanel.setBorder(BorderFactory.createMatteBorder(0,4,0,4,Color.BLACK));
    		add(buttonsPanel, BorderLayout.CENTER);
    			System.out.println("Adding textfields");
    			textFieldsPanel = new JPanel();
    			textFieldsPanel.setBackground(Color.WHITE);
    			textFieldsPanel.setBorder(BorderFactory.createMatteBorder(4,4,2,4,Color.BLACK));
    			textFieldsPanel.setLayout(new FlowLayout());
    			textFieldsPanel.add(xInput);
    			textFieldsPanel.add(operatorInput);
    			textFieldsPanel.add(yInput);
    			textFieldsPanel.add(answerOutput);
    			System.out.println("TextFields added");
    		add(textFieldsPanel, BorderLayout.NORTH);
    			System.out.println("Adding status output");
    			statusPanel = new JPanel();
    			statusPanel.setBackground(Color.WHITE);
    			statusPanel.setBorder(BorderFactory.createMatteBorder(2,4,4,4,Color.BLACK));
    			statusPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    			statusPanel.add(statusOutput);
    			System.out.println("Status output added");
    		add(statusPanel, BorderLayout.SOUTH);

  4. #4
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    I set this JPanel as the content pane in both the applet version and the standalone version of the program.
    You can quite easily make one version for both. And I don't have the experience that what works for an Applet doesn't for an Application or v.v.
    (except Applet-restrictions). So like Fubarable says, it must be a bug. Make an SSCCE (Small Self Contained Compiling Example) with only the essentials (but two buttons: in a calculator they can share one ActionListener if you extend JButton) and try to make that work first (and post it if you fail). Then elaborate on that.
    Last edited by Jodokus; 05-22-2011 at 01:33 AM. Reason: spelling
    No bug ever had to calculate its fitnessfunction.

  5. #5
    ryanmk54's Avatar
    ryanmk54 is offline Member
    Join Date
    May 2011
    Posts
    18
    Rep Power
    0

    Default

    I created a very simple html page to contain the applet and it worked out perfectly. It must have been something that was wrong with my first html page. I'll take a look at it.:)

Similar Threads

  1. How to display the console window?
    By yma16 in forum IntelliJ IDEA
    Replies: 0
    Last Post: 05-19-2011, 08:32 AM
  2. Netbeans output window won't display
    By jujubinaj in forum New To Java
    Replies: 1
    Last Post: 12-16-2010, 03:51 AM
  3. Do not want to set DISPLAY and run X11 window server
    By shafi2all in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2009, 06:02 AM
  4. i want to display decimal values in frame window
    By santhosh_el in forum AWT / Swing
    Replies: 4
    Last Post: 03-16-2009, 10:07 AM
  5. Replies: 1
    Last Post: 08-08-2008, 04:20 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •