SlideShare a Scribd company logo
Throughout the semester, we have been working on command line applications. While the
command line can be a powerful form of interacting with the computer, most modern
applications have a graphical user interface, or GUI. This program will give you some initial
experience making GUI applications with Swing.
1. Write an original GUI application in Java using Swing. The program can be a simple game, or
an application that demonstrates some of the capabilities of Swing, for example.
2. The application must do something non-trivial that is controlled by GUI components such as
buttons, text boxes, drop-down boxes, etc. For example, it might draw different things, or change
colors, based on button presses.
3. The GUI elements should be layed out reasonably using layout managers.
4. At least one element in your GUI program besides the title bar must include your name.
Suggestions
Get the skeleton of your GUI working first. First get the buttons drawing properly, then go on to
listen to and respond to events.
Initially, hook up the event listeners so that they print something to the console when a button is
pressed. That way you can know that your code is getting events.
If your program will draw shapes, make a subclass of JPanel called "DrawPanel" or something
like that to draw the objects and your name. Override the "paintComponent" method of this
class.
Solution
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); } }

More Related Content

PPTX
Graphical User Interface (Gui)
PPTX
Chap 1 - Introduction GUI.pptx
PDF
Z blue introduction to gui (39023299)
PDF
PPTX
UNIT 2 SWIGS for java programing by .pptx
PPTX
Lesson1 Introduction to GUI and Java Swing Components.pptx
PPTX
JavaSwingndAWTProgrammingforBeginner.pptx
Graphical User Interface (Gui)
Chap 1 - Introduction GUI.pptx
Z blue introduction to gui (39023299)
UNIT 2 SWIGS for java programing by .pptx
Lesson1 Introduction to GUI and Java Swing Components.pptx
JavaSwingndAWTProgrammingforBeginner.pptx

Similar to Throughout the semester, we have been working on command line applic.pdf (20)

DOC
java swing notes in easy manner for UG students
PPT
14a-gui.ppt
PPTX
Programming 2: Java Midterm Week Twelve.
PDF
Ingles 2do parcial
PPT
Chapter 5 GUI for introduction of java and gui .ppt
PPT
Chap1 1 1
PPT
Chap1 1.1
PDF
Unit-2 swing and mvc architecture
PPTX
PPT
Swing and AWT in java
PDF
Swingpre 150616004959-lva1-app6892
PPTX
A Simple Java GUI Application.pptx
PPT
28 awt
PPT
03_GUI.ppt
PPTX
GUI Programming using NetBeans.pptx
PPTX
GUI Programming using NetBeans (1).pptx
PPTX
Swing component point are mentioned in PPT which helpgul for creating Java GU...
PDF
GUI.pdf
PPT
Unit 1- awt(Abstract Window Toolkit) .ppt
PPT
Slot04 creating gui
java swing notes in easy manner for UG students
14a-gui.ppt
Programming 2: Java Midterm Week Twelve.
Ingles 2do parcial
Chapter 5 GUI for introduction of java and gui .ppt
Chap1 1 1
Chap1 1.1
Unit-2 swing and mvc architecture
Swing and AWT in java
Swingpre 150616004959-lva1-app6892
A Simple Java GUI Application.pptx
28 awt
03_GUI.ppt
GUI Programming using NetBeans.pptx
GUI Programming using NetBeans (1).pptx
Swing component point are mentioned in PPT which helpgul for creating Java GU...
GUI.pdf
Unit 1- awt(Abstract Window Toolkit) .ppt
Slot04 creating gui

More from birajdar2 (20)

PDF
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
PDF
Project selection methods and the project portfolio play an importan.pdf
PDF
javaFix in the program belowhandle incomplete data for text fil.pdf
PDF
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
PDF
In the class we extensively discussed a generic singly linked list i.pdf
PDF
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
PDF
Given below is an issue that you have identified as an issue in a ret.pdf
PDF
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
PDF
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
PDF
Consider the following segment table What are the physical addresse.pdf
PDF
Can you explain the movement of ions and ion channel activity during.pdf
PDF
Calculate the implied stock price assuming an EBITDA multiple of 11..pdf
PDF
Below is the graph of a polynomial function f with real coefficients.pdf
PDF
Are higher than average sea surface temperatures associated with a g.pdf
PDF
A table of values of an increasing function F is shown. Use the table.pdf
PDF
A polygenic trait is determined by a single gene with many different.pdf
PDF
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
PDF
21. What is the relationship between the maximum size of aggregates a.pdf
PDF
Which of the following are organizer molecules in the avian PMZ is a.pdf
PDF
What are the five stages of team development Describe each stage an.pdf
public static ArrayListInteger doArrayListSearchSmallest(int nu.pdf
Project selection methods and the project portfolio play an importan.pdf
javaFix in the program belowhandle incomplete data for text fil.pdf
James can row 14 km downstream in a river in 2 hours. He takes 7 hou.pdf
In the class we extensively discussed a generic singly linked list i.pdf
How do hydrophobic and hydrophilic hormones differ in their speeds a.pdf
Given below is an issue that you have identified as an issue in a ret.pdf
Explain Aquinas 5 proofs of God, being sure to identify the Aris.pdf
Exercise 7. Show that if C(0) (the punctured plane) and U C are conf.pdf
Consider the following segment table What are the physical addresse.pdf
Can you explain the movement of ions and ion channel activity during.pdf
Calculate the implied stock price assuming an EBITDA multiple of 11..pdf
Below is the graph of a polynomial function f with real coefficients.pdf
Are higher than average sea surface temperatures associated with a g.pdf
A table of values of an increasing function F is shown. Use the table.pdf
A polygenic trait is determined by a single gene with many different.pdf
4. Phil is conducting a seed germination experiment. He places 3 gro.pdf
21. What is the relationship between the maximum size of aggregates a.pdf
Which of the following are organizer molecules in the avian PMZ is a.pdf
What are the five stages of team development Describe each stage an.pdf

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
01-Introduction-to-Information-Management.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Lesson notes of climatology university.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
01-Introduction-to-Information-Management.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
A systematic review of self-coping strategies used by university students to ...
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GDM (1) (1).pptx small presentation for students
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
human mycosis Human fungal infections are called human mycosis..pptx
Complications of Minimal Access Surgery at WLH
Lesson notes of climatology university.

Throughout the semester, we have been working on command line applic.pdf

  • 1. Throughout the semester, we have been working on command line applications. While the command line can be a powerful form of interacting with the computer, most modern applications have a graphical user interface, or GUI. This program will give you some initial experience making GUI applications with Swing. 1. Write an original GUI application in Java using Swing. The program can be a simple game, or an application that demonstrates some of the capabilities of Swing, for example. 2. The application must do something non-trivial that is controlled by GUI components such as buttons, text boxes, drop-down boxes, etc. For example, it might draw different things, or change colors, based on button presses. 3. The GUI elements should be layed out reasonably using layout managers. 4. At least one element in your GUI program besides the title bar must include your name. Suggestions Get the skeleton of your GUI working first. First get the buttons drawing properly, then go on to listen to and respond to events. Initially, hook up the event listeners so that they print something to the console when a button is pressed. That way you can know that your code is getting events. If your program will draw shapes, make a subclass of JPanel called "DrawPanel" or something like that to draw the objects and your name. Override the "paintComponent" method of this class. Solution 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);