170k views
5 votes
Creating a Graphical User Interface in Java

1. Write the Java statement that creates a JPanel named payroll Panel.
2. Write the Java statement that creates a JButton named saveButton.

2 Answers

4 votes

Answer:

JPanel PayrollPanel=new JPanel();

JButton saveButton=new JButton("Save");

A full code snippet and screen shot is provided in the explanation section

Step-by-step explanation:

import java.awt.*;

import javax.swing.*;

public class TestClass {

TestClass() {

JFrame f= new JFrame("Payroll Panel");

JPanel payrollPanel=new JPanel();

payrollPanel.setBounds(10,20,200,200);

payrollPanel.setBackground(Color.gray);

JButton saveButton=new JButton("Save");

saveButton.setBounds(50,100,80,30);

saveButton.setBackground(Color.yellow);

payrollPanel.add(saveButton);

f.add(payrollPanel);

f.setSize(400,400);

f.setLayout(null);

f.setVisible(true);

}

public static void main(String args[]) {

new TestClass();

}

}

User Matt Razza
by
4.5k points
2 votes

Answer:

JPanel PayrollPanel=new JPanel();

JButton saveButton=new JButton("Save");

A full code snippet and screen shot is provided in the explanation section

Step-by-step explanation:

import java.awt.*;

import javax.swing.*;

public class TestClass {

TestClass() {

JFrame f= new JFrame("Payroll Panel");

JPanel payrollPanel=new JPanel();

payrollPanel.setBounds(10,20,200,200);

payrollPanel.setBackground(Color.gray);

JButton saveButton=new JButton("Save");

saveButton.setBounds(50,100,80,30);

saveButton.setBackground(Color.yellow);

payrollPanel.add(saveButton);

f.add(payrollPanel);

f.setSize(400,400);

f.setLayout(null);

f.setVisible(true);

}

public static void main(String args[]) {

new TestClass();

}

}

Creating a Graphical User Interface in Java 1. Write the Java statement that creates-example-1
User Mcrute
by
5.0k points