LottoMadness.java 1 Create the file for the program shown here 2. Run programs.
ID: 3709566 • Letter: L
Question
LottoMadness.java 1 Create the file for the program shown here 2. Run programs. [NOTE: There might be errors in the code you need to fix.] 3. Describe what is happening in the areas highlighted in yellow 4. Upload your screenshots of the program to Canvas. package com.IST240Apps import java.awt. import javax.swing. public class LottoMadness extends JFrame // set up row JPanel rowlnew JPanelo ButtonGroup Optionnew ButtonGroup) JCheckBox quickpick new JCheckBox( "Quick Pick", false); JCheckBox Personal new JCheckBox("Personal Ealse) // set up row 2 JPanel ownew JPanel)i JLabel numbersLabel new JLabel"Your Picks JLabel.RIGHT) JTextField Numbersnew JTextFicld6) JLabel winnersLabel-new JLabel(Winners:JLabel.RIGHT JTextField winnersnew JTextFieldt61: // set up row 3 JPanel ow3new JPanel JButton stopnew JButton( "Stop" JButton play new JButton( "Play JButton resetnew JButton( "Reset) // set up row 4 JPanel row4new JPanel)i JLabel got3Label new JLabel("3 of 6: ,JLabe1.RIGHT) JTextField got3 new JTextField("0) JLabel got4Label = new JLabel( "4 of 6: ", JLabel . RIGHT); JTextField gotA = new JTextField("0"); JLabel got5Label new JLabel( "5 of 6: ", JLabel.RIGHT) JTextField got5 new JTextField(0) JLabel got6Label new JLabel("6 of 6: JLabel.RIGHT) TextField got6 = new JTextField("0", 10); JLabel drawingsLabel new JLabel( "Drawings:JLabel.RIGHT): JTextField drawings new JTextField(0) JLabel yearsLabel new JLabel( "Years: ", JLabel.RIGHT): JTextField years = new JTextField(); public LottoNadness super("Lotto Madness" setsize (500, 400); setDefaultcloseoperation(JFrame.EXIT ON CLOSE) GridLayout Layout new GridLayout (5, 1, 10, 10); setLayout (layout) FlowLayout Layout 1 FlowLayout (FlowLayout "CENTER, = new 10, 10) option.add(quickpick):Explanation / Answer
Answer:
//set up row 4
//Here we are creating a object of JLabel with label text and horizontal align to the Right side
//and also creating a object of JTextField with string param which will be displayed into text field.
JLabel got3Label = new JLabel("3 of 6", JLabel.RIGHT);
JTextField got3 = new JTextField("0");
JLabel got4Label = new JLabel("4 of 6", JLabel.RIGHT);
JTextField got4 = new JTextField("0");
JLabel got5Label = new JLabel("5 of 6", JLabel.RIGHT);
JTextField got5 = new JTextField("0");
JLabel got6Label = new JLabel("6 of 6", JLabel.RIGHT);
JTextField got6 = new JTextField("0", 10);
JLabel drawingsLabel = new JLabel("Drawings", JLabel.RIGHT);
JTextField got6 = new JTextField("0");
JLabel yearsLabel = new JLabel("Years", JLabel.RIGHT);
JTextField years = new JTextField();
//Here we are creating object of GridLayout with 2 rows, 7 columns, 10 hgap(horizontal gap) and 10 vgap(verticle gap)
GridLayout layout2 = new GridLayout(2,7,10,10);
//setting the grid layout to panel
row2.setLayout(layout2);
//adding label to the panel
row2.add(numbersLabel);
for(int i =0; i< 6;i++){
//creating a JTextField objects and asign to the ith position.
numbers[i] = new JTextField();
//add JTextField object of ith position into the row2 panel
row2.add(numbers[i]);
}
//adding label to the panel
row2.add(winnersLabel);
for(int i =0; i<6; i++){
//creating a JTextField objects and asign to the ith position.
winners[i] = new JTextField();
//set the ith position text field as editable true.
winners[i].setEditable(true);
//add JTextField object of ith position into the row2 panel
row2.add(numbers[i]);
}
add(row2);
//Here we are creating object of GridLayout with 2 rows, 3 columns, 20 hgap(horizontal gap) and 10 vgap(verticle gap)
//then adding labels into the panel and set text field editable false then added into panel
GridLayout layout4 = new GridLayout(2, 3, 20, 10);
row4.setLayout(layout4);
row4.add(got3Label);
got3.setEditable(false);
row4.add(got3);
row4.add(got4Label);
got4.setEditable(false);
row4.add(got4);
row4.add(got5Label);
got5.setEditable(false);
row4.add(got5);
row4.add(got6Label);
got6.setEditable(false);
row4.add(got6);
row4.add(drawingsLabel);
drawings.setEditable(false);
row4.add(drawings);
row4.add(yearsLabel);
years.setEditable(false);
row4.add(years);
add(row4);
Note: For commenting i have consider only highlighted code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.