Java assignment. Create the frame like the above visual that contains three butt
ID: 3837419 • Letter: J
Question
Java assignment.
Create the frame like the above visual that contains three buttons (Generate, Queue, List. Notice the color for each of the labels) and a bottom portion that allows some information to be displayed. When the Generate button is clicked, come up with five random numbers between 1 and 100. Push each of the numbers on to a stack and display the stack in the lower portion. (The button | can be pressed up to three times. Each time the button is pressed, another five numbers are generated and are pushed on to the stack. The display would be updated accordingly. After three times, display, stack is full and display the numbers in the stack. Note that the display does not pop the numbers from the stack) When the Queue button is clicked, pop each of the numbers from the stack and place it in a queue. Display all the information from the queue in the lower portion. (The button can be pressed many times. If there is nothing in the stack, then display stack is empty and display the contents of the queue. If there is nothing in the queue, then display empty queue) When the List button is clicked, remove each of the numbers from the queue and place it in a list. Display all the information from the list in the lower portion of the frame. (The button can be pressed many times. If there is nothing in the queue, then display queue is empty and display the contents of the list. If there is nothing in the list, then display the list is empty) When the Vector button is clicked, remove each of the numbers from the list and place it in a Vector. Display all the information from the Vector in the lower portion of the frame. (The button can be pressed many times. If there is nothing in the list, then display list is empty and display the contents of Vector. If there is nothing in the Vector, then display the Vector is empty) When the Map button is clicked, remove each of the numbers from the Vector and place it in a Map. Since the Map also requires a key, for each number that is being placed in the values part of the map, generate a number between 1 and 100 for its key (lf the same number is generated, it merely means that you are overwriting one of the old values. This would mean that your Map may only contain a subset of the values from your Vector) Display all the information from the Map in the lower portion of the frame. (The button can be pressed many times. If there is nothing in the Vector, then display vector is empty and display the contents of the Map. If there is nothing in the Map, then display the Map is empty) (Caution: when you import the various packages, you may run into a compilation problem because there are two List classes, one in each of the different packages. You have two solutions: One is to declare the List variable using its fully qualified name Java.util.List a = ____ Or when importing the awt package, import the specific classes that you need such as Import.java.awt.Color along with whatever else you need from the awt package. Also when removing from collections that are index based, remember to use the index 0 when removing inside a for loop. This ensures that you don't go out of bounds)Explanation / Answer
public void createControls(Composite parent) { myComposite = new Composite(parent, SWT.NONE); GridLayout detailsSideGridLayout = new GridLayout(); detailsSideGridLayout.numColumns = 1; myComposite.setLayout(detailsSideGridLayout); GridDatamyGridData = new GridData(); myGridData.horizontalAlignment = SWT.FILL; myGridData.grabExcessHorizontalSpace = true; myGridData.verticalAlignment = SWT.FILL; myGridData.grabExcessVerticalSpace = true; myComposite.setLayoutData(myGridData); deComposite = new Composite(myComposite, SWT.NONE); RowLayout dgGridLayout = new RowLayout(SWT.HORIZONTAL); deComposite.setLayout(deGridLayout); GridData deGridData = new GridData(); deGridData.horizontalAlignment = SWT.FILL; deGridData.grabExcessHorizontalSpace = true; LinkLabel createDetailsde = createDetailsde(deComposite); createDetailsde.setLayoutData(deGridData); //Add another button createLinkLabel(createDetailsde) myComposite.layout(); private LinkLabel createDetailsde(Composite detailsComposite) { // TODO check resource manager implementation LinkLabel linkLabel = new LinkLabel(detailsComposite, SWT.NONE); linkLabel.setText("test"); //$NON-NLS-1$ return linkLabel; } private LinkLabel createLinkLabel(Composite detailsComposite) { LinkLabel linkLabel = new LinkLabel(detailsComposite, SWT.NONE); linkLabel.setText("test2"); //$NON-NLS-1$ return linkLabel; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class example { public static void main (String[] args){ JFrame frame = new JFrame("Test"); frame.setVisible(true); frame.setSize(500,200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); frame.add(panel); JButton button = new JButton("generate1"); panel.add(button); button.addActionListener (new Action1()); JButton button2 = new JButton("queue"); panel.add(button2); button.addActionListener (new Action2()); JButton button = new JButton("list"); panel.add(button); button.addActionListener (new Action3()); JButton button = new JButton("vector"); panel.add(button); button.addActionListener (new Action4()); JButton button = new JButton("map"); panel.add(button); button.addActionListener (new Action5()); } static class Action1 implements ActionListener { public void actionPerformed (ActionEvent e) { JFrame frame2 = new JFrame("Clicked"); frame2.setVisible(true); frame2.setSize(200,200); JLabel label = new JLabel("you clicked me"); JPanel panel = new JPanel(); frame2.add(panel); panel.add(label); } } static class Action2 implements ActionListener { public void actionPerformed (ActionEvent e) { JFrame frame3 = new JFrame("OKNO 3"); frame3.setVisible(true); frame3.setSize(200,200); JLabel label = new JLabel("kliknales"); JPanel panel = new JPanel(); frame3.add(panel); panel.add(label); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.