Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with keeping the gui one size

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Help with keeping the gui one size

    i have my little program here and it all works and everything but i would like the GUI to stay this size i have it set. Right now when you run it and you drag a corner it changes the whole look of the GUI and moves everything around. I was wondering if there is a way to keep it the size i have it now without it being able to change?

    package wlodmgcalc;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class wlocalc extends JFrame  implements ActionListener {
    	static final long serialVersionUID = 0L;
     
    	JTextField atk;
    	JComboBox elementBox;
    	JButton calculate;
    	JLabel damageTotal;
    	JLabel warning;
    	String[] elements;
    	int cbox;
    	String atkNum;
     
    	public wlocalc() {
    		super("WLO Damage Calculator");
    		setSize(180, 230);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
    		setLayout(flow);
     
    		JPanel row1 = new JPanel();
            JLabel atkLabel = new JLabel("Atk/Matk:");
    		row1.add(atkLabel);
    		atk = new JTextField(7);
    		row1.add(atk);
    		add(row1);
     
    		JPanel row2 = new JPanel();
    		JLabel elementLabel = new JLabel("Element:");
    		row2.add(elementLabel);
    		String[] elements = { "Wind", "Fire", "Water", "Earth" };
    		elementBox = new JComboBox(elements);
    		elementBox.addActionListener(this);
    		row2.add(elementBox);
    		add(row2);
     
    		JPanel row3 = new JPanel();
    		FlowLayout flowbutton = new FlowLayout(FlowLayout.CENTER, 50, 10);
    		row3.setLayout(flowbutton);
    		calculate = new JButton("Calculate");
    		calculate.addActionListener(this);
    		row3.add(calculate);
    		add(row3);
     
    		JPanel row4 = new JPanel();
    		JLabel totalLabel = new JLabel("Damage: ");
    		row4.add(totalLabel);
    		add(row4);
     
    		JPanel row5 = new JPanel();
    		damageTotal = new JLabel(atkNum);
    		row5.add(damageTotal);
    		add(row5);
     
    		JPanel row6 = new JPanel();
    		warning = new JLabel("Damage is to weak element");
    		row6.add(warning);
    		add(row6);
     
    		setVisible(true);
    	}
     
    	public void actionPerformed(ActionEvent event) {
    		String atknum = atk.getText();
    		int atkNumber = Integer.parseInt(atknum);
    		String element = (String)elementBox.getSelectedItem();
    		if (atkNumber == 0) {
    			damageTotal.setText("0");
    		} else if (element == "Wind") {
    			cbox = (int) ((atkNumber * 1.4 + 0 - 2 * 0.98) * 1.3);
    		} else if (element == "Fire") {
    			cbox = (int) ((atkNumber * 1.4 + 0 - 2 * 0.98) * 1.6);
    		} else if (element == "Water") {
    			cbox = (int) ((atkNumber * 1.4 + 0 - 2 * 0.98) * 1.4);
    		} else if (element == "Earth") {
    			cbox = (int) ((atkNumber * 1.4 + 0 - 2 * 0.98) * 1.3);
    		}
     
    		String pressed = event.getActionCommand();
    		if (pressed.equals("Calculate")) {
    			damageTotal.setText("" + cbox);
    		}
    		}
     
    	public static void main(String[] args) {
    		wlocalc dmg = new wlocalc();
    	}
    }

    Any and help is appreciated if you want to see how i mean just run that and maximize the window


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with keeping the gui one size

    Did you check the API?

    Frame (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with keeping the gui one size

    A comment on your code: } else if (element == "Wind") {
    Use the equals() method to compare the contents of Strings not the == operator

  4. #4
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Help with keeping the gui one size

    thats perfect ty

    @norm ill go back and change that thanks a lot guys

    edit: i changed the == to .equals now and used setResizable(false) and now everything is good

    thanks very much guys
    Last edited by derekxec; July 27th, 2011 at 05:15 PM.

Similar Threads

  1. [SOLVED] Keeping Negative Fractions
    By Kerrigan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 10th, 2011, 05:03 PM
  2. keeping a tally
    By Neo in forum Java Theory & Questions
    Replies: 3
    Last Post: February 3rd, 2011, 06:36 AM
  3. Keeping objects in webservice
    By ashleypursglove in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 16th, 2010, 12:02 PM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  5. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM