Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: GUI problem

  1. #21
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    This compiler message is saying that it can't find a Frame method called setPreferredSize() that takes two int arguments.

    What you do here is check the method name (ie make sure you are calling the method you mean to, and that you haven't made any typos). Then check that the arguments are correct.

    The API documentation is your friend. Perhaps you mean setPreferredSize() or perhaps you mean setSize(). If the latter is the case you may want to think about what phi.pack() does at the end of the method.

  2. #22
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    --------------------Configuration: <Default>--------------------
    E:\mkdl\archive1\jp219\MainProgram.java:30: cannot resolve symbol
    symbol : method setPreferredSize (java.awt.Dimension)
    location: class java.awt.Frame
    phi.setPreferredSize(new Dimension(800,500));
    ^
    1 error

    Process completed.

  3. #23
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    E:\mkdl\archive1\jp219\MainProgram.java:30: cannot resolve symbol
    symbol : method setPreferredSize (java.awt.Dimension)
    Did you read the documentation?

    (I've just realised this is the third direct question I've asked in this thread.)

  4. #24
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default

    I understand. The only problem was the "phi.pack" method.

  5. #25
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by kevzspeare View Post
    I understand. The only problem was the "phi.pack" method.
    That second error suggests deeper problems. What version of Java are you using?

  6. #26
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  7. #27
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by mtyoung View Post
    have you import java.awt.Dimension
    import java.awt.*;

    Also the compiler message as posted says "symbol : method setPreferredSize (java.awt.Dimension)" and not "symbol : class Dimension". Hence my questions about whether the documentation for this method had been read and what Java version the OP was using.

  8. #28
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default new code.

    my java version is j2sdk 1.4.2_17

    the new code is as follows:

    Java Code:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class MainProgram
    {
    	String name0x1;
    	TravellingPackage prog[] = new TravellingPackage[10];
    	Frame phi;
    	Button beta;
    	CheckboxGroup tau;
    	TextField alpha1, alpha2, alpha3, nu, chi;
    	Label lambda, lambda2, theta1, theta2, theta3,
    	theta3a, theta3b, theta3c, theta4;
    	Panel header, pi, pi2, pi3, pi3a, pi4, pi5, footer;
    	public static void main (String args[]) throws IOException
    	{
    		MainProgram main = new MainProgram();
    		main.addComponents();
    	}
    	public MainProgram()
    	{
    		phi = new Frame("MKDL Travel Agency System Ver. I");
    	}
    	public void addComponents()
    	{
    		File data = new File ("report.txt");
    		int q = 0;
    		phi = new Frame("MKDL Travel Agency System Ver. I");
    		phi.setLayout(null);
    		phi.setSize(500,500);
    		phi.setResizable(false);
    		phi.setLocation(100,100);
    		phi.setBackground(Color.gray);
    		header = new Panel();
    		pi = new Panel();
    		pi2 = new Panel();
    		pi3 = new Panel();
    		pi3a = new Panel();
    		pi4 = new Panel();
    		pi5 = new Panel();
    		footer = new Panel();
    		header.setSize(400,50);
    		header.setLocation(50,50);
    		header.setBackground(Color.orange);
    		pi.setSize(400,50);
    		pi.setLocation(50,100);
    		pi.setBackground(Color.blue);
    		pi2.setSize(400,50);
    		pi2.setLocation(50,150);
    		pi2.setBackground(Color.red);
    		pi3.setSize(400,50);
    		pi3.setLocation(50,200);
    		pi3.setBackground(Color.yellow);
    		pi3a.setSize(400,50);
    		pi3a.setLocation(50,250);
    		pi3a.setBackground(Color.yellow);
    		pi4.setSize(400,50);
    		pi4.setLocation(50,300);
    		pi4.setBackground(Color.magenta);
    		pi5.setSize(400,50);
    		pi5.setLocation(50,350);
    		pi5.setBackground(Color.green);
    		footer.setSize(400,50);
    		footer.setLocation(50,400);
    		footer.setBackground(Color.pink);
    		beta = new Button("Calculate Fare");
    		tau = new CheckboxGroup();
    		lambda = new Label("MKDL Travel Agency System Ver. I");
    		lambda2 = new Label("(C) 2009 MKDL Studios. All rights reserved.");
    		alpha1 = new TextField("",2);
    		alpha2 = new TextField("",2);
    		alpha3 = new TextField("",2);
    		theta1 = new Label("Agent's Name");
    		theta2 = new Label("Travelling Method");
    		theta3 = new Label("Number of Tourists");
    		theta3a = new Label("Age Below 2");
    		theta3b = new Label("Age 2-16");
    		theta3c = new Label("Age Above 16");
    		theta4 = new Label("Total Fare:");
    		nu = new TextField("",30);
    		chi = new TextField("",20);
    		Checkbox bus = new Checkbox("Bus", true, tau);
    		Checkbox cruise = new Checkbox("Cruise", false, tau);
    		Checkbox plane = new Checkbox("Airplane", false, tau);
    		header.add(lambda);
    		pi.add(theta1);
    		pi.add(nu);
    		pi2.add(theta2);
    		pi2.add(tau);
    		pi3.add(theta3);
    		pi3a.add(theta3a);
    		pi3a.add(alpha1);
    		pi3a.add(theta3b);
    		pi3a.add(alpha2);
    		pi3a.add(theta3c);
    		pi3a.add(alpha3);
    		pi4.add(beta);
    		pi5.add(theta4);
    		pi5.add(chi);
    		footer.add(lambda2);
    		phi.add(header);
    		phi.add(pi);
    		phi.add(pi2);
    		phi.add(pi3);
    		phi.add(pi3a);
    		phi.add(pi4);
    		phi.add(pi5);
    		phi.add(footer);
    		phi.setVisible(true);
    	}
    	
    }
    Upon compilation:

    --------------------Configuration: <Default>--------------------
    E:\mkdl\archive1\jp219\MainProgram.java:90: cannot resolve symbol
    symbol : method add (java.awt.CheckboxGroup)
    location: class java.awt.Panel
    pi2.add(tau);
    ^
    1 error

    Process completed.

  9. #29
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  10. #30
    timkd127 is offline Member
    Join Date
    Dec 2008
    Posts
    41
    Rep Power
    0

    Default

    you should split all the code thats building the individual panels into there own method. This will make it easier to keep it organized and find errors. Out of curiosity isnt the fact that its in AWT not matter. All of the methods that hes calling have a corresponding SWING method with the same name? just wonderin

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •