Results 1 to 5 of 5
- 05-21-2011, 04:54 AM #1
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.
-
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.One more thing, is there a way to make the applet fit the size of the components like the pack() method in a window?
- 05-21-2011, 10:10 PM #3
It is a lot of code, so unless you want it in full, I'll just display the initialization.
initialization
displaying the panelsJava 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
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);
- 05-22-2011, 12:18 AM #4
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.I set this JPanel as the content pane in both the applet version and the standalone version of the program.
(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 12:33 AM. Reason: spelling
No bug ever had to calculate its fitnessfunction.
- 05-23-2011, 09:50 PM #5
Similar Threads
-
How to display the console window?
By yma16 in forum IntelliJ IDEAReplies: 0Last Post: 05-19-2011, 07:32 AM -
Netbeans output window won't display
By jujubinaj in forum New To JavaReplies: 1Last Post: 12-16-2010, 02:51 AM -
Do not want to set DISPLAY and run X11 window server
By shafi2all in forum AWT / SwingReplies: 1Last Post: 07-26-2009, 05:02 AM -
i want to display decimal values in frame window
By santhosh_el in forum AWT / SwingReplies: 4Last Post: 03-16-2009, 09:07 AM -
how to display chat window in both source and destination machine
By bu.pradeep in forum NetworkingReplies: 1Last Post: 08-08-2008, 03:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks