Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java how to make a gui

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Foo{

  public static void main(String[] args) {

    JFrame f = new JFrame("A JFrame");
    f.setSize(250, 250);
    f.setLocation(300,200);
    final JTextArea textArea = new JTextArea(10, 40);
    f.getContentPane().add(BorderLayout.CENTER, textArea);
    final JButton button = new JButton("Click Me");
    f.getContentPane().add(BorderLayout.SOUTH, button);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            textArea.append("Button was clicked
");

        }
    });

    f.setVisible(true);

  }

}
Comment

simple gui in java

//Usually you will require both swing and awt packages
// even if you are working with just swings.
import javax.swing.*;
import java.awt.*;
class gui {
    public static void main(String args[]) {

        //Creating the Frame
        JFrame frame = new JFrame("Chat Frame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);

        //Creating the MenuBar and adding components
        JMenuBar mb = new JMenuBar();
        JMenu m1 = new JMenu("FILE");
        JMenu m2 = new JMenu("Help");
        mb.add(m1);
        mb.add(m2);
        JMenuItem m11 = new JMenuItem("Open");
        JMenuItem m22 = new JMenuItem("Save as");
        m1.add(m11);
        m1.add(m22);

        //Creating the panel at bottom and adding components
        JPanel panel = new JPanel(); // the panel is not visible in output
        JLabel label = new JLabel("Enter Text");
        JTextField tf = new JTextField(10); // accepts upto 10 characters
        JButton send = new JButton("Send");
        JButton reset = new JButton("Reset");
        panel.add(label); // Components Added using Flow Layout
        panel.add(tf);
        panel.add(send);
        panel.add(reset);

        // Text Area at the Center
        JTextArea ta = new JTextArea();

        //Adding Components to the frame.
        frame.getContentPane().add(BorderLayout.SOUTH, panel);
        frame.getContentPane().add(BorderLayout.NORTH, mb);
        frame.getContentPane().add(BorderLayout.CENTER, ta);
        frame.setVisible(true);
    }
}
Comment

how to create a gui in java

import javax.swing.*;
   class gui{
      public static void main(String args[]){
        JFrame frame = new JFrame("My First GUI");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,300);
       JButton button1 = new JButton("Press");
       frame.getContentPane().add(button1);
       frame.setVisible(true);
     }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java substring based on delimiter 
Java :: how to use split on a file name java 
Java :: how to add the last area of an array in java 
Java :: generic classes in java 
Java :: how to check if user is logged in firebase android and then load another activity 
Java :: spring boot onetomany relationsion 
Java :: android setTextColor not working 
Java :: fixed length array powershell PSv5+ 
Java :: mac java version terminal 
Java :: java program to Check given String is contians number or not 
Java :: get arguments in fragment kotlin 
Java :: java Overridding example 
Java :: binary to int java 
Java :: java.util.HashMap has generic type parameters, please use GenericTypeIndicator instead 
Java :: To enable CORS in the MVC Java config 
Java :: what is whitespace in java 
Java :: java swing get frame size 
Java :: java input - how to read a string 
Java :: get data from database sqlite android 
Java :: read qr code from image java 
Java :: Java Exception handling using Java throw 
Java :: public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); } } 
Java :: print anything in java 
Java :: list constructor java 
Java :: android generate random int 
Java :: can i call another function from main hava 
Java :: java static variable 
Java :: Android Number Picker format JAVA 
Java :: kkkkkkkkkkkkkk 
Java :: java benchmark time 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =