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
Need to write a cookie with a url var
Not sure if its possible, but I need to write a cookie with a url.So this would write 2232 as the cookie for ID.http://www.example.com/redirect.php?ID=2232Ultimately, I'm working on a pixel tracking
controlling/creating accounts with privileges
hi all,i'm trying to figure out how i can create/control account with privileges, for instance an Administrator creates an account but gives it guest privileges (able to see data but not edit, or
PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see when I view source, versus what I want to see … I am having image re-sizing issues that
Session variable help
I'm having a very troubling issue. Maybe I'm just looking over something but I have looked at the code for several hours now, making small adjustments here and there to try to fix this problem.
Save data in input fields when they press "BACK BUTTON"
Hi, this is html form: And let's say they get a error "Please enter ur title must be more then 3 character" then they click the BACK BUTTON AND ALL THERE DATA IS GONE!!How i fix?Code:
returning data from an ssh2_exec()
here's what i got.$conn = ssh2_connect($this->_host); ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect"); //build command line to include
php multiple action on submit
I have a form which says:<form enctype='multipart/form-data' method='post' action='process.php' target='_blank'>I need to call process.php on submit or on clicking submit button. Now
help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me push in the right direction?
Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.I guess this is because of the loose typing of PHP,