Question: 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

1 Expert Approved Answer
Step: 1 Unlock

To enhance the GUI by adding labels and a submit button you can use JLabel for indicating what data ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!