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
Step: 1
To enhance the GUI by adding labels and a submit button you can use JLabel for indicating what data ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started