Hello,
I recently started making an applet to calculate certain values for airplanes. However, Gui has proved to be a problem. The JFormattedTextFields I am using have worked perfectly fine until I discovered this problem. Basically, when you enter numbers into the text boxes and then re size the browser or window, when run from my IDE, they change size based on how much space the number takes up. This messes up the layout and is quite annoying. My only suspicion is that resizing the window calls some event that updates their sizes..though why they change size I do not know. I am using box layout.
I would post the images, but I do not have enough posts yet, this being my first so those links should do.
Normal default layout on start of applet:
i583.photobucket.com/albums/ss271/a13w/Normal.png
Resized layout with input:
i583.photobucket.com/albums/ss271/a13w/Resized.png
This is the code:
Code: import java.awt.*;import java.applet.*;import java.awt.event.*;import javax.swing.JApplet;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JFormattedTextField;import javax.swing.JTextField;import javax.swing.JPanel;import javax.swing.BoxLayout;import javax.swing.Box;import javax.swing.text.NumberFormatter;public class WeightBalanceCalcuator extends JApplet { Container contentPane; Listener listen; //------------Calculator JObjects--------- //Main Calculator Frame JPanel calculatorPanel; JPanel calculatorPanelRow0; //Blank Row JPanel calculatorPanelRow1; JPanel calculatorPanelRow2; JPanel calculatorPanelRow3; JPanel calculatorPanelRow4; JPanel calculatorPanelRow5; JPanel calculatorPanelRow6; JPanel calculatorPanelRow7; //Blank Row JPanel calculatorPanelRow8; //Row 1 Components JLabel emptyWeightLabel; JFormattedTextField emptyWeight; JFormattedTextField emptyLever; JFormattedTextField emptyMoment; //Row 2 Components JLabel frontWeightLabel; JFormattedTextField frontWeight; JFormattedTextField frontLever; JFormattedTextField frontMoment; //Row 3 Components JLabel rearWeightLabel; JFormattedTextField rearWeight; JFormattedTextField rearLever; JFormattedTextField rearMoment; //Row 4 Components JLabel fuelWeightLabel; JFormattedTextField fuelWeight; JFormattedTextField fuelLever; JFormattedTextField fuelMoment; //Row 5 Components JLabel oilWeightLabel; JFormattedTextField oilWeight; JFormattedTextField oilLever; JFormattedTextField oilMoment; //Row 6 Components JLabel baggageWeightLabel; JFormattedTextField baggageWeight; JFormattedTextField baggageLever; JFormattedTextField baggageMoment; //Row 8 Components JLabel totalWeightLabel; JFormattedTextField totalWeight; JLabel totalMomentLabel; JFormattedTextField totalMoment; //---------------------------------------- public void init() { listen = new Listener(); initCalculatorPanel(this); } //Declares and adds all graphical components which have to do with the calculator section public void initCalculatorPanel(JApplet window) { contentPane = window.getContentPane(); //Initalize Panels calculatorPanel = new JPanel(); calculatorPanelRow0 = new JPanel(); //Blank Row calculatorPanelRow1 = new JPanel(); calculatorPanelRow2 = new JPanel(); calculatorPanelRow3 = new JPanel(); calculatorPanelRow4 = new JPanel(); calculatorPanelRow5 = new JPanel(); calculatorPanelRow6 = new JPanel(); calculatorPanelRow7 = new JPanel(); calculatorPanelRow8 = new JPanel(); calculatorPanel.setBackground(Color.WHITE); calculatorPanelRow0.setBackground(Color.WHITE); calculatorPanelRow1.setBackground(Color.WHITE); calculatorPanelRow2.setBackground(Color.WHITE); calculatorPanelRow3.setBackground(Color.WHITE); calculatorPanelRow4.setBackground(Color.WHITE); calculatorPanelRow5.setBackground(Color.WHITE); calculatorPanelRow6.setBackground(Color.WHITE); calculatorPanelRow7.setBackground(Color.WHITE); calculatorPanelRow8.setBackground(Color.WHITE); contentPane.add(calculatorPanel, BorderLayout.NORTH); calculatorPanel.setLayout(new GridLayout(9,1)); calculatorPanel.add(calculatorPanelRow0); calculatorPanel.add(calculatorPanelRow1); calculatorPanel.add(calculatorPanelRow2); calculatorPanel.add(calculatorPanelRow3); calculatorPanel.add(calculatorPanelRow4); calculatorPanel.add(calculatorPanelRow5); calculatorPanel.add(calculatorPanelRow6); calculatorPanel.add(calculatorPanelRow7); calculatorPanel.add(calculatorPanelRow8); calculatorPanelRow1.setLayout(new BoxLayout(calculatorPanelRow1, BoxLayout.X_AXIS)); calculatorPanelRow2.setLayout(new BoxLayout(calculatorPanelRow2, BoxLayout.X_AXIS)); calculatorPanelRow3.setLayout(new BoxLayout(calculatorPanelRow3, BoxLayout.X_AXIS)); calculatorPanelRow4.setLayout(new BoxLayout(calculatorPanelRow4, BoxLayout.X_AXIS)); calculatorPanelRow5.setLayout(new BoxLayout(calculatorPanelRow5, BoxLayout.X_AXIS)); calculatorPanelRow6.setLayout(new BoxLayout(calculatorPanelRow6, BoxLayout.X_AXIS)); calculatorPanelRow8.setLayout(new BoxLayout(calculatorPanelRow8, BoxLayout.X_AXIS)); //Initalize elements //Initalize Row 1 Components emptyWeightLabel = new JLabel("Aircraft empty weight:"); emptyWeightLabel.setHorizontalAlignment(JLabel.RIGHT); emptyWeight = new JFormattedTextField(new NumberFormatter()); emptyWeight.setMinimumSize(new Dimension(73 ,0)); emptyWeight.addFocusListener(listen); emptyLever = new JFormattedTextField(new NumberFormatter()); emptyMoment = new JFormattedTextField(new NumberFormatter()); emptyMoment.setEditable(false); //Initalize Row 2 Components frontWeightLabel = new JLabel("Pilot & front passenger weight:"); frontWeightLabel.setHorizontalAlignment(JLabel.RIGHT); frontWeight = new JFormattedTextField(new NumberFormatter()); frontWeight.addFocusListener(listen); frontLever = new JFormattedTextField(new NumberFormatter()); frontMoment = new JFormattedTextField(new NumberFormatter()); frontMoment.setEditable(false); //Initalize Row 3 Components rearWeightLabel = new JLabel("Rear passengers weight:"); rearWeightLabel.setHorizontalAlignment(JLabel.RIGHT); rearWeight = new JFormattedTextField(new NumberFormatter()); rearWeight.addFocusListener(listen); rearLever = new JFormattedTextField(new NumberFormatter()); rearMoment = new JFormattedTextField(new NumberFormatter()); rearMoment.setEditable(false); //Initalize Row 4 Components fuelWeightLabel = new JLabel("Fuel weight:"); fuelWeightLabel.setHorizontalAlignment(JLabel.RIGHT); fuelWeight = new JFormattedTextField(new NumberFormatter()); fuelWeight.addFocusListener(listen); fuelLever = new JFormattedTextField(new NumberFormatter()); fuelMoment = new JFormattedTextField(new NumberFormatter()); fuelMoment.setEditable(false); //Initalize Row 5 Components oilWeightLabel = new JLabel("Oil weight:"); oilWeightLabel.setHorizontalAlignment(JLabel.RIGHT); oilWeight = new JFormattedTextField(new NumberFormatter()); oilWeight.addFocusListener(listen); oilLever = new JFormattedTextField(new NumberFormatter()); oilMoment = new JFormattedTextField(new NumberFormatter()); oilMoment.setEditable(false); //Initalize Row 6 Components baggageWeightLabel = new JLabel("Baggage weight:"); baggageWeightLabel.setHorizontalAlignment(JLabel.RIGHT); baggageWeight = new JFormattedTextField(new NumberFormatter()); baggageWeight.addFocusListener(listen); baggageLever = new JFormattedTextField(new NumberFormatter()); baggageMoment = new JFormattedTextField(new NumberFormatter()); baggageMoment.setEditable(false); //Initalize Row 8 Components totalWeightLabel = new JLabel("Total weight:"); totalWeight = new JFormattedTextField(new NumberFormatter()); totalWeight.setEditable(false); totalMomentLabel = new JLabel("Total moment:"); totalMoment = new JFormattedTextField(new NumberFormatter()); totalMoment.setEditable(false); //Add calculator panel elements, divided into rows //Add row 1 components calculatorPanelRow1.add(Box.createHorizontalGlue()); calculatorPanelRow1.add(Box.createRigidArea(new Dimension(80,0))); calculatorPanelRow1.add(emptyWeightLabel); calculatorPanelRow1.add(emptyWeight); calculatorPanelRow1.add(new JLabel("lb")); calculatorPanelRow1.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow1.add(emptyLever); calculatorPanelRow1.add(new JLabel("inch")); calculatorPanelRow1.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow1.add(emptyMoment); calculatorPanelRow1.add(new JLabel("inch-pounds")); calculatorPanelRow1.add(Box.createRigidArea(new Dimension(30,0))); //Add row 2 components calculatorPanelRow2.add(Box.createHorizontalGlue()); calculatorPanelRow2.add(Box.createRigidArea(new Dimension(30,0))); calculatorPanelRow2.add(frontWeightLabel); calculatorPanelRow2.add(frontWeight); calculatorPanelRow2.add(new JLabel("lb")); calculatorPanelRow2.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow2.add(frontLever); calculatorPanelRow2.add(new JLabel("inch")); calculatorPanelRow2.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow2.add(frontMoment); calculatorPanelRow2.add(new JLabel("inch-pounds")); calculatorPanelRow2.add(Box.createRigidArea(new Dimension(30,0))); //Add row 3 components calculatorPanelRow3.add(Box.createHorizontalGlue()); calculatorPanelRow3.add(Box.createRigidArea(new Dimension(63,0))); calculatorPanelRow3.add(rearWeightLabel); calculatorPanelRow3.add(rearWeight); calculatorPanelRow3.add(new JLabel("lb")); calculatorPanelRow3.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow3.add(rearLever); calculatorPanelRow3.add(new JLabel("inch")); calculatorPanelRow3.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow3.add(rearMoment); calculatorPanelRow3.add(new JLabel("inch-pounds")); calculatorPanelRow3.add(Box.createRigidArea(new Dimension(30,0))); //Add row 4 components calculatorPanelRow4.add(Box.createHorizontalGlue()); calculatorPanelRow4.add(Box.createRigidArea(new Dimension(138,0))); calculatorPanelRow4.add(fuelWeightLabel); calculatorPanelRow4.add(fuelWeight); calculatorPanelRow4.add(new JLabel("lb")); calculatorPanelRow4.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow4.add(fuelLever); calculatorPanelRow4.add(new JLabel("inch")); calculatorPanelRow4.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow4.add(fuelMoment); calculatorPanelRow4.add(new JLabel("inch-pounds")); calculatorPanelRow4.add(Box.createRigidArea(new Dimension(30,0))); //Add row 5 components calculatorPanelRow5.add(Box.createHorizontalGlue()); calculatorPanelRow5.add(Box.createRigidArea(new Dimension(146,0))); calculatorPanelRow5.add(oilWeightLabel); calculatorPanelRow5.add(oilWeight); calculatorPanelRow5.add(new JLabel("lb")); calculatorPanelRow5.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow5.add(oilLever); calculatorPanelRow5.add(new JLabel("inch")); calculatorPanelRow5.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow5.add(oilMoment); calculatorPanelRow5.add(new JLabel("inch-pounds")); calculatorPanelRow5.add(Box.createRigidArea(new Dimension(30,0))); //Add row 6 components calculatorPanelRow6.add(Box.createHorizontalGlue()); calculatorPanelRow6.add(Box.createRigidArea(new Dimension(111,0))); calculatorPanelRow6.add(baggageWeightLabel); calculatorPanelRow6.add(baggageWeight); calculatorPanelRow6.add(new JLabel("lb")); calculatorPanelRow6.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow6.add(baggageLever); calculatorPanelRow6.add(new JLabel("inch")); calculatorPanelRow6.add(Box.createRigidArea(new Dimension(20,0))); calculatorPanelRow6.add(baggageMoment); calculatorPanelRow6.add(new JLabel("inch-pounds")); calculatorPanelRow6.add(Box.createRigidArea(new Dimension(30,0))); //Add row 8 Components calculatorPanelRow8.add(Box.createRigidArea(new Dimension(133,0))); calculatorPanelRow8.add(totalWeightLabel); calculatorPanelRow8.add(totalWeight); calculatorPanelRow8.add(new JLabel("lb")); calculatorPanelRow8.add(Box.createRigidArea(new Dimension(55,0))); calculatorPanelRow8.add(totalMomentLabel); calculatorPanelRow8.add(totalMoment); calculatorPanelRow8.add(new JLabel("inch-pounds")); calculatorPanelRow8.add(Box.createRigidArea(new Dimension(30,0))); calculatorPanelRow8.add(Box.createHorizontalGlue()); } //Updates moment text fields public void updateMoment() {// emptyMoment.setText(); } //Updates both bottom total text fields public void updateTotal() { if (weightFieldsNotEmpty()) { totalWeight.setText(String.valueOf(Double.parseDouble(emptyWeight.getText()) + Double.parseDouble(frontWeight.getText()) + Double.parseDouble(rearWeight.getText()) + Double.parseDouble(fuelWeight.getText()) + Double.parseDouble(oilWeight.getText()) + Double.parseDouble(baggageWeight.getText()))); if (momentFieldsNotEmpty()) { totalMoment.setText(String.valueOf(Double.parseDouble(emptyMoment.getText()) + Double.parseDouble(frontMoment.getText()) + Double.parseDouble(rearMoment.getText()) + Double.parseDouble(fuelMoment.getText()) + Double.parseDouble(oilMoment.getText()) + Double.parseDouble(baggageMoment.getText()))); } } }; //Checks to see if any weight field is empty, if so returns false private boolean weightFieldsNotEmpty() { if (emptyWeight.getText().equals("") || frontWeight.getText().equals("")|| rearWeight.getText().equals("") || fuelWeight.getText().equals("") || oilWeight.getText().equals("") || baggageWeight.getText().equals("") ) return false; return true; } //Checks to see if any moment field is empty, if so returns false private boolean momentFieldsNotEmpty() { if (emptyMoment.getText().equals("") || frontMoment.getText().equals("")|| rearMoment.getText().equals("") || fuelMoment.getText().equals("") || oilMoment.getText().equals("") || baggageMoment.getText().equals("") ) return false; return true; } //Listens for when a weight text box is unfocuses then updates Moment and Totals. public class Listener implements FocusListener { public Listener() { } public void focusGained(FocusEvent e) { System.out.println(emptyWeight.getBounds().getWidth()); } public void focusLost(FocusEvent e) { updateMoment(); updateTotal(); } }} Thank you
Weekly Calendar
Hi, I am looking at creating a weekly calendar. The calendar will read from Monday - Sunday. Does anyone know of any examples or tutorails on how I can achieve this, as I have tried searching without
UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbnails in different folders however it is uploading the image and saving it in the folder /photos/ then
Date Format
Hi there,I have a date format like this right now:Sat, 17 Oct 2009 17:04:00 I need to turn that into:2009-10-17T17:04:00ZMy thought process was to remove with regex "Sat," and then just
Looping Problem
I've got a client that has a database with about 200 events at any given time. I'm trying to loop through the dates based on a form and show the title of the event if the start date of the form
Form Help
Here is the form:Line number On/Off | Expand/Contract<? include("../include/session.php"); ?> <?php if ($submit) { $sql = "UPDATE productimages
how can i make a .gif images for my site
Dear Friends ,Pls solve my problem , I am starting making new site but i dont know how can i make a .gif images for my site . Is there any editor to make my .gif images comfortably
Time-based image rotation script
I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the script to show day.jpg from 6 AM to 6 PM, and to show night.jpg from 6 PM to 6 AM.I also need the
PHP4 to PHP5 Conversion
Hi Everyone,I am working on a site that is built up on PHP4 and each page is being started from <? instead of <?php as of PHP5.I want to convert this <? to <?php on every
Can I call a class inside a function?
I have a class written in another file that handles my image resizing.Can I do this (php says I can't calling a non-existent class), but I know its there becuase the require doesn't fail aboveCode:
How to get variable value on next page
Hello friends i am working on payentry page ..there i have this code......... Code: $str="select MAX(PSRN) from paymajor";$result=mysql_query($str) or