#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    28
    Rep Power
    0

    Using Java Swing class, how do I make my window bigger!?


    can someone help me figure out how to make my window bigger on this program? I know it's not complete, but should at least be able to make the window larger, I'd think! And how to get it to open and start in the center of the screen!?

    here is my code so far:

    Code:
    package financialCalc;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class FinancialCalc extends JFrame
    {
    	private JPanel welcomePanel, greetingPanel, buttonPanel, blank, blank2;
    	private JLabel message;
    	private JButton autoPmt, mortPmt, homeAfford, costOfMin, exit;
    	
    	
    	public FinancialCalc()
    	{
    		super("Financial Calculator Application");
    		
    		
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		setLayout(new BorderLayout());
    		
    		
    		
    		
    		
    		buildWelcomeMenu();
    		
    		add(greetingPanel, BorderLayout.NORTH);
    		add(welcomePanel, BorderLayout.CENTER);
    		add(buttonPanel, BorderLayout.SOUTH);
    		add(blank, BorderLayout.EAST);
    		add(blank2, BorderLayout.WEST);
    		
    		
    		pack();
    		setVisible(true);
    		
    		
    		
    		
    	}
    		
    	
    	public void buildWelcomeMenu()
    	{
    		welcomePanel = new JPanel();
    		welcomePanel.setLayout(new GridLayout(4,1));
    		//welcomePanel.setSize(720, 1080);
    		
    		
    		autoPmt = new JButton("Auto loan payment calculator");
    		autoPmt.setMnemonic(KeyEvent.VK_A);
    		autoPmt.addActionListener(new AutoButtonListener());
    		
    		mortPmt = new JButton("Mortgage payment calculator");
    		mortPmt.setMnemonic(KeyEvent.VK_M);
    		mortPmt.addActionListener(new MortButtonListener());
    		
    		homeAfford = new JButton("How much home can you afford?");
    		homeAfford.setMnemonic(KeyEvent.VK_H);
    		homeAfford.addActionListener(new HomeButtonListener());
    		
    		costOfMin = new JButton("True cost of paying the minimum payment");
    		costOfMin.setMnemonic(KeyEvent.VK_C);
    		costOfMin.addActionListener(new CostMinButtonListener());
    		
    		buttonPanel = new JPanel();
    		exit = new JButton("Exit");
    		exit.setMnemonic(KeyEvent.VK_E);
    		exit.addActionListener(new ExitButtonListener());
    		buttonPanel.add(exit);
    		
    		welcomePanel.add(autoPmt);
    		welcomePanel.add(mortPmt);
    		welcomePanel.add(homeAfford);
    		welcomePanel.add(costOfMin);
    	
    		
    		greetingPanel = new JPanel();
    		message = new JLabel("Welcome to the Financial Calculations Application");
    		greetingPanel.add(message);
    		
    		blank = new JPanel();
    		blank2 = new JPanel();
    		
    	}
    	
    	
    	private class AutoButtonListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    	
    			
    			
    		}
    	
    	}
    	
    	private class MortButtonListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    	
    			
    			
    		}
    	
    	}
    	
    	private class HomeButtonListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    	
    			
    			
    		}
    	
    	}
    	
    	private class CostMinButtonListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    	
    			
    			
    		}
    	
    	}
    	
    	
    	private class ExitButtonListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			System.exit(0);			
    		}
    	
    	}
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	public static void main(String[] args) 
    	{
    		new FinancialCalc();
    
    	}
    
    }
    thanks so much for your help in advance!
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    You can set the size of the window by calling a Window class method.

    The setLocationRelativeTo(null) method will center the window.

IMN logo majestic logo threadwatch logo seochat tools logo