how to build a gui in java

Solutions on MaxInterview for how to build a gui in java by the best coders in the world

showing results for - "how to build a gui in java"
Matys
06 Oct 2017
1import java.awt.BorderLayout;
2import java.awt.event.ActionEvent;
3import java.awt.event.ActionListener;
4
5import javax.swing.JButton;
6import javax.swing.JFrame;
7import javax.swing.JTextArea;
8
9public class Foo{
10
11  public static void main(String[] args) {
12
13    JFrame f = new JFrame("A JFrame");
14    f.setSize(250, 250);
15    f.setLocation(300,200);
16    final JTextArea textArea = new JTextArea(10, 40);
17    f.getContentPane().add(BorderLayout.CENTER, textArea);
18    final JButton button = new JButton("Click Me");
19    f.getContentPane().add(BorderLayout.SOUTH, button);
20    button.addActionListener(new ActionListener() {
21
22        @Override
23        public void actionPerformed(ActionEvent e) {
24            textArea.append("Button was clicked\n");
25
26        }
27    });
28
29    f.setVisible(true);
30
31  }
32
33}
Tommaso
07 Nov 2017
1import java.awt.BorderLayout;//Just some imports that are needed
2import java.awt.GridLayout;//Just some imports that are needed
3import java.awt.event.ActionEvent;//Just some imports that are needed
4import java.awt.event.ActionListener;//Just some imports that are needed
5
6import javax.swing.BorderFactory;//Just some imports that are needed
7import javax.swing.JButton;//Just some imports that are needed
8import javax.swing.JFrame;//Just some imports that are needed
9import javax.swing.JLabel;//Just some imports that are needed
10import javax.swing.JPanel;//Just some imports that are needed
11
12public class GUI implements ActionListener{//If there is a red line after writing GUI its cause you have no code for the bit that's after implements so just hover over gui and just press "add unimplemented methods"
13	
14	int count = 0;//a VAR for the function of the button for the number of clicks
15	private JLabel label;
16	private JPanel panel;
17	private JFrame frame;
18	
19	
20	public GUI(){//This implements for the constructor that is being create in the void main, Here you can make frames for the gooooooey and define its characteristics :P
21		
22		//JFrame - we have removed this from the line below to make a var that we can use in multiple methods {a}
23		frame = new JFrame();//This sets the frame for the goooooooooey so the user can customise it to their needs
24		
25		JButton button = new JButton("Howdy");//This is used to make a button
26		button.addActionListener(this);//This refers to the class that we are using like GUI implements Action listener
27		
28		//JLabel {a}
29		label = new JLabel("Number of clicks: 0"); //This is used to add a label to our program
30		
31		//JPanel {a}
32		panel = new JPanel();//This sets the panel for the gooey for the user so that they can add elements, delete import etc etc
33		panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));//This makes a border object for the goooey and the number in the field describes the distance it should be from the borders of the gui
34		panel.setLayout(new GridLayout(0,1));// This is the default constructor for the borders/grids
35		panel.add(button);//This adds the button ( basically packing like btn.pack())
36		panel.add(label);//This adds the button (packs)
37		
38		frame.add(panel, BorderLayout.CENTER);
39		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
40		frame.setTitle("Our GOOEY");//sets the title
41		frame.pack();//like py
42		frame.setVisible(true);//kinda literal this just lets the dev choose if the user can see this or not
43	}
44	
45	public static void main(String[] args) {
46		new GUI();//Creates a constructor but this needs to be implemented to actually show us the gui window
47
48	}
49
50	@Override
51	public void actionPerformed(ActionEvent e) {//After implementing the unimplemented methods this autogenerated method is initiated to help us write our code in for the action we need to perform
52		count++;//Increases the count by 1
53		label.setText("Number of clicks: " + count);//This just changes the text of the label like lable.config("Hey") and then adds the number of clicks to the string
54		
55	}
56
57}
58
queries leading to this page
gui application in javamake java gui appsgui using javasimple gui example in javacreate gui in javasimple gui with javajava how to create a simple guimake gui app javajava gui builder programjava program with guimake a gui in javagui in java tutorialjava create a gui toolmaking java gui from codehow to build a gui in javajava swing in eclipse tutorialhow to make a gui with javahow to make a professional gui with javasimple gui javagui based java programcreate a gui in javahow far java gui can dogui program in javabuilding a gui in java 8run gui java from eclipsejava gui tutorial in eciplesejava gui code examplehow to create gui class in javajava how to create a guicreating a java guihow to amke gui javahow to make a gui in java 8java make a guihow to create gui for java applicationhow to code gui at javajava gui tutorial usingmaking a simple gui in javamake gui in javagui in java examplescreate gui with javabuilding guis in javahow to create gui in eclipse using javajava gui example codehow to build a gui javacreate a gui javahow to make gui in javamake gui for application javahow to make gui things with javacreate java guiscreate a java with guiwhat kind of java application can i make with gui 3fhow to use a gui with javajava gui designjava make guimaking a java guicreate a software gui in javahow to amke a java guimaking a gui in javahow to make gui application in javahow to develop gui app in javagui application javabasic java guibasic gui javajava gui exampleshow to program gui javacreating gui in javabuilding a gui in javajava gui ideascan you do gui with javajava swing make guihow can i make the gui of my java programhow to create java guismake a gui online for javajava making own gui libraryhowto make simple gui in javabuild gui javahow to call an gui in javahow to make a gui app with javagui project in javahow ro make a gui in javasimple java guijava how make guimake java guibuilding guis javajava make object guibest way to make java guigui in javajava making guijava windos apliction guiusing java to create guisnew way to do gui on javagui tutorial javajava design guisoftware to make java guihow to make a gui javahow do you create a gui in javacreate gui in eclipse javahow to make your own gui library in java build gui in javahow to create a gui javahow make gui in javahow to make guiin javahow to develop gui with javajava create simple guiwe can use a class to create a gui in javajava how to design a guijava gui programming tutorialgui using swing in javahow to create gui based application in javajava gui tutorial explainedmake gui javahow to make gui in java tutorialcreating a gui app javahow to create a program using java guiwhat is the best way of creating gui 27s in javacreate gui javahow to create a gui in javajava create a user interfacesoftware gui in javajava create guidhow to make a gui for javagui java examplemaking a ui in javado you write gui in java in work 3fhow to build gui in javajava create a simple uihow to make guis in javahow to build java guicreate gui application in javahow to setup gui in javabest way to create a gui in javajava gui examplecreate gui interface in eclipsebasic gui program in javacreating gui in swing javamake gui project in javajava create a gui examplebest way to make a java guihow to create java guijava creating a guihow to create a simple gui in javawhat is used to make java guihow to create a java guibuild a gui in javajava simple gui programshould i make gui with javahow to make a gui in javacreate a gui application in javagui programs in javajava how to build guihow to program a gui in javahow to make gui javahow to build a gui with javajava tutorial of guigui java tutorialhow to make a gui application in javasetup gui method in javamake gui app in javabuild gui with javasimple gui program in javahow to setup gui class in javajava how to start a guihow to make gui with javajava how to create guijava create a gui exampleswhat are the different ways to create a java gui applicationjava make your own gui frameworkgui app in javagui app with javabasic steps for gui javamake gui with javabest way to make gui in javahow to make a clickable user interface in javahow to create gui for java programjava gui how tohow to develop java guijava make your own gui softwarewhat do people typically use to make java guissimple gui code in javajava basic guihow to creat java gui eclipsesimple gui in javacreating java programs with guisteps to creating a gui application in javacreating a gui in javahow to make a java application with guiwrite gui program javahow to create a gui in java swingwhy to use gui in javahow to create a good gui in javawhat to use for make gui through javagui examples javabasic java gui programhow to create a gui for javahow to write a gui javagui design javahow to create gui in javajava create graphical interfacejava how to make a guijava easiest way to create guibest way ot make a gui in javahow to code gui in javamake simple java guijava create a guijava create guihow to gui javabuild gui app with javahow to make a java guicreating gui javahow to make a gui os in javajava how to make guimaking gui app java gui with javajava how to write your own gui librarycreate java gui using designer gui in javahow to use gui in javamaking java guis the right waycreate gui in eclipse jframehow to make gui in swing javalearn gui in javajava gui tutorialhow to design a gui javahow to build a gui in java