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
Lack of simpleXML Documentation
What is up with this.Look at: http://www.php.net/manual/en/function.simplexml-load-file.phpThere is no documentation with the ns parameter of that function and I am currently trying to deal with
Issues: PHP Forms -Clearing
I've tried looking online before actually asking for help, but I've been looking for about the past 3-5 hours and have found nothing that'll help me.This is a project for school, and well I have to
Most basic form question ever?
Hello,I want to use this snippet to make sure the fields in a form are ok before processing it.Code: <FORM method="post">To:<input type="text"
Pagination won't carry results past page 2.
Hi all,I've worked out my pagination script and its paginating fine until I click next from page 2 at which point it stops displaying results. I know its something really simple, but can't see what
Help with PHP Calendar code...
Hello, I'm new to this forum and I'm glad I found it.I wrote this code for a PHP calendar as an assignment for college.It works fine, but I also want today's day to show in another color and I can't
values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a database. the form submits some data to one table, and other data to another table. my problem is that
word wrap in emails help needed
Hello, I understand how wordwrap works in php and have used it well before. However when I used wordwrap on a variable that is going to be emailed it puts the line breaks in well before it should.
UDS 4.0 Datatype issue
UDS 4.0.322 -- connecting to NI Labview 9.0
max() problem
I have a while loop to get image names. Code: $imagequery = mysql_query("SELECT * FROM ad_image WHERE user='$user' AND ad='$adnr' ORDER BY `picorder` ASC")or die(mysql_error());$totpics =
This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the data from the (and only that one) last record for every single day in the log file. Each record as