Part 4 Use WindowBuilder Busy Box In this one you will create a user interface t
ID: 3811218 • Letter: P
Question
Part 4 Use WindowBuilder
Busy Box
In this one you will create a user interface that displays many of the available widgets in Swing. It doesn’t actually need to do anything – you don’t need to hear the events for this one. The purpose of this exercise is to make you familiar with some of the widgets that you have for creating interfaces in Swing.
Include in your Busy Box examples of…
Note: I’m not positive of the names of these, I’m remembering them in a mix of C#, Android, SWT, and Swing GUI classes. They are mostly the same, or similar names. If you can’t find one assume I got the name wrong and don’t stress over it. Keep in mind my objective here is to encourage you to explore what is available, and play with them a little bit. Your Busy Box should give me the impression that you have been exploring the widgets that are available.
JTabbedPane
JScrollPane
JList
JButton
JTextField
JComboBox
JCheckBox
JRadioButtonGroup
JRadioButton
JTable
JImage
Take a screen shot of your BusyBox and put it on the discussion board. Comment on a couple of other’s busy boxes.
Include the code and some screen shots of your busy box in the assignment submission
Part 6
A useful GUI. If you have the 10th edition of the Liang text, he deos a good job of describing JavaFX. If you have the 9th ed., he describes using Swing. For the following exercise you can use either Swing or JavaFX.
Give me a clear indication of which you are using. I’ve heard that some people are mixing them. That sounds horrible to me – pick one.
Create an application that has a button that has “Enter your info.” When clicked it will present a dialog that has labels and text boxes that allow the user to enter their name, email, and phone number. The dialog will have buttons OK and Cancel.
When the user clicks Cancel, the dialog will go away without doing anything else.
When the user clicks OK, the user’s information will be extracted from the dialog, and dumped out on the console.
Notice that you only are listening for Click events.
Deliverables:
The presentation should be in order, and should demonstrate everything that would convince the reader that you have met the objectives. Code, output from running the code, screen shots where appropriate.
There are 6 parts; I expect to see 6 labeled sections that are clearly indicated 1 - 6. All of the code, output from running the code should be included and enough screenshots to convince me that you have met the objectives of this assignment.
Explanation / Answer
Part 4:
package john;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.ButtonGroup;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.SwingConstants;
import javax.swing.ScrollPaneConstants;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import java.awt.FlowLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.LineBorder;
public class WindowsPro {
private JFrame frame;
private JTextField txtJtextfield;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
WindowsPro window = new WindowsPro();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public WindowsPro() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1000, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(tabbedPane, BorderLayout.NORTH);
JPanel panel = new JPanel();
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
panel.setAlignmentX(0);
panel.setBackground(new Color(0, 0, 0));
tabbedPane.addTab("New tab1", null, panel, null);
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(153, 204, 51));
tabbedPane.addTab("New tab2", null, panel_1, null);
JPanel panel_2 = new JPanel();
panel_2.setBackground(new Color(0, 0, 255));
tabbedPane.addTab("New tab3", null, panel_2, null);
JCheckBox chckbxJcheckbox = new JCheckBox("JCheckBox");
panel.add(chckbxJcheckbox);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setViewportView(new JLabel("Welcome to JScrollPaneWelcome"));
scrollPane.setPreferredSize(new Dimension(300, 100));
panel.add(scrollPane, BorderLayout.WEST);
JButton btnNewButton = new JButton("JButton");
btnNewButton.setBackground(new Color(102, 102, 51));
panel.add(btnNewButton, BorderLayout.EAST);
txtJtextfield = new JTextField();
txtJtextfield.setText("JTextField");
txtJtextfield.setHorizontalAlignment(SwingConstants.LEFT);
panel.add(txtJtextfield, BorderLayout.SOUTH);
txtJtextfield.setColumns(10);
JComboBox comboBox = new JComboBox();
comboBox.setToolTipText("Select Value");
comboBox.setModel(new DefaultComboBoxModel(new String[] {"JList", "JList1", "JList2", "JList3"}));
panel.add(comboBox, BorderLayout.CENTER);
JRadioButton rdbtnOne = new JRadioButton("one");
panel.add(rdbtnOne);
JRadioButton rdbtnTwo = new JRadioButton("two");
panel.add(rdbtnTwo);
ButtonGroup group = new ButtonGroup();
group.add(rdbtnOne);
group.add(rdbtnTwo);
JRadioButton JRadioButton = new JRadioButton("two");
panel.add(JRadioButton);
table = new JTable();
table.setBorder(new LineBorder(new Color(0, 0, 0), 3, true));
table.setModel(new DefaultTableModel(
new Object[][] {
{null, "", ""},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
},
new String[] {
"ABC", "BCD", "DEF"
}
));
frame.getContentPane().add(table, BorderLayout.WEST);
}
}