Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

add to the code: I need help with making a more defined textfields that have a label indication what data is expected to be entered.

add to the code: I need help with making a more defined textfields that have a label indication what data is expected to be entered. Enhance the GUI by adding a Submit button and allowing the user to enter their own data in the textfields.


import javax.swing.*;

public class Widget {

public static void main(String[] args) {

// Creating a JFrame & JPanel as required

JFrame frame = new JFrame("Widget"); // with title as Widget

JPanel panel = new JPanel();

// Creating 3 JTextFields

JTextField nameField = new JTextField(20); JTextField ageField = new JTextField(10); JTextField addressField = new JTextField(50);

nameField.setText("John Doe"); ageField.setText("Age 26"); addressField.setText("Silver Spring, Maryland");

// Adding fields in panel

panel.add(nameField); panel.add(ageField); panel.add(addressField);

// Adding panel in Frame

frame.add(panel);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Setting size of frame width & height

frame.setSize(600, 300);

// Making JFrame visible

frame.setVisible(true); } }

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

To enhance the GUI by adding labels and a submit button you can use JLabel for indicating what data ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions