0

[I am trying a create a layout like a picture below. I am new to Java programming.]When I am trying to run this. There is no error or anything and nothing displays. Console stops automatically. Kindly help me.

Example

package completeJavaReference; 
import java.awt.FlowLayout; 
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel; 
import javax.swing.JTextField;
------------------------------------------------------------------------


    public class tryingProject extends JFrame {
        public static final long serialVersionUID = 1L;//Eclipse added
        public static JLabel carname;
        public static JLabel price, make, year, trim, category, VIN, model,bodytype;
        public static JLabel dealerinfo, ID, URL, Name;
        public static JTextField priceTextField, makeTextField, yearTextField, 
        trimTextField, categoryTextField, VINTextField, modelTextField, 
        bodytypeTextField;
        private static JTextField dealerinfoTextField, IDTextField, URLTextField, 
        NameTextField;

        public void createComponents() {
            carname = new JLabel("Honda Civic");
            price = new JLabel("Price: ");
            make = new JLabel("Make: ");
            year = new JLabel("Year:");
            trim = new JLabel("Trim:");
            category = new JLabel("Category:");
            VIN = new JLabel("VIN:");
            model = new JLabel("Model:");
            bodytype = new JLabel("Body Type");
            priceTextField = new JTextField(10);
            makeTextField = new JTextField(10);
            yearTextField = new JTextField(10);
            trimTextField = new JTextField(10);
            categoryTextField = new JTextField(10);
            VINTextField = new JTextField(10);
            modelTextField = new JTextField(10);
            bodytypeTextField = new JTextField(10);
            dealerinfo = new JLabel("Dealer Info");
            ID = new JLabel("Dealer ID:");
            URL = new JLabel("URL:");
            Name = new JLabel("Dealer Name");
            dealerinfoTextField = new JTextField(10);
            IDTextField = new JTextField(10);
            URLTextField = new JTextField(10);
            NameTextField = new JTextField(10);
        }
        public void createLayout(){
            JFrame frame = new JFrame("Vehicle Window");
            JPanel Panel1 = new JPanel(new FlowLayout());
            JPanel Panel2 = new JPanel(new GridLayout(4, 3));
            JPanel Panel3 = new JPanel(new FlowLayout());
            Panel1.add(carname);
            Panel2.add(price);
            Panel2.add(priceTextField);
            Panel2.add(make);
            Panel2.add(makeTextField);
            Panel2.add(year);
            Panel2.add(yearTextField);
            Panel2.add(trim);
            Panel2.add(trimTextField);
            Panel2.add(category);
            Panel2.add(categoryTextField);
            Panel2.add(VIN);
            Panel2.add(VINTextField);
            Panel2.add(model);
            Panel2.add(modelTextField);
            Panel2.add(year);
            Panel2.add(yearTextField);
            Panel3.add(dealerinfo);
            Panel3.add(dealerinfoTextField);
            Panel3.add(ID);
            Panel3.add(IDTextField);
            Panel3.add(URL);
            Panel3.add(URLTextField);
            Panel3.add(Name);
            Panel3.add(NameTextField);
            frame.getContentPane().add(Panel1);
            frame.getContentPane().add(Panel2);
            frame.getContentPane().add(Panel3);
            frame.setTitle("Vechicle Details");
            frame.setSize(200, 200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        public static void main(String args[]) 
        {
        new tryingProject();
        }
    }
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Daffy
  • 1
  • 1
  • 1
    Step back for a minute, have a look at you requirements. As far as I can see, you have two containers and a label you need to layout at the top level, I would personally focus on understand how to make that work first. Then take each of the other containers, and break those down and figure out how to make those work – MadProgrammer Apr 12 '17 at 00:54
  • Sorry to be a party pooper, but before concerning yourself with layouts, you should first work on learning how to create decent OOP-compliant Java classes with non-static instance variables and non-static methods. Your over-use of the static modifier suggests a much more foundational problem than that of which layout is the best to use. Start with the Java tutorial, [Lesson: Classes and Objects](http://docs.oracle.com/javase/tutorial/java/javaOO/index.html) and move from there. – Hovercraft Full Of Eels Apr 12 '17 at 00:57
  • yes. I am in phase of studying from basics. But I tried creating a layout something like the picture . Where can be the problem? – Daffy Apr 12 '17 at 01:07
  • `new tryingProject()` makes a Frame. You never **show** the Frame... And your other methods are also never called... I wouldn't suggest GUI programming to someone new to Java / programming. – OneCricketeer Apr 12 '17 at 01:16

0 Answers0