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
Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and relivant city data.However, I found out that the city is showing up only one time when I have can
get the country of visitor and display content based on that
Hello all,I have seen that Google analytics can tell you where a visitor is coming from and I want to do something similar. But I would like to add the functionality of redirecting a user based on his
PHP Login
Hey!I got this shopcart code online, am trying to modify it but am getting an error when i try and login as an administrator.Am new to php ......so let me know if you can help Source code for
Little problem with form insertion in MySQL, Please help!!!
Hi!,I'm a little bit new with php and I have a little issue here. I created a webform to insert some infos into a MySQL database. The weird thing is that some of the infos is correctly inserted and
Dynamic Data + Sql Server 2005 Enterprise?
Hi! I have just started to learn ASP.NET, and it looks like it is quite a lot to learn. Im not really sure where I should begin, but I have watched the Dynamic Data
multiple recipients + dbuser mail recall
Hello,I am building a php login script.When the user registers the script will send him a confimation email using this codemail($usr_email, "Login Details", $message, "From:
True way to see if action was successful?
If this is a good way to see if action was successful to continue:Code: function changeGameState($GameId) { mysql_query("UPDATE challenges SET status=status+1 WHERE id='$GameId'");
How to sum these output values
Hi
need to add "sizes" to shopping cart
Hey guys, I am trying to figure out a way to add a "size" selector on to this bit of code. I added a way to view it in the "zoom.php" page and also to select a size from the sizes
Problem with passing variables
I'm not really a php programmer so I'm really struggling with this issue. I have a banner script that is supposed to send people to an affiliate site and pass the parameters along with it.For