Can you please help me to run this Java program? I have no idea why it is not running.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@SuppressWarnings({"unchecked", "rawtypes"})
public class SmartPhonePackages extends JFrame
{
private static final long serialVersionID=
6548829860028144965L;
private static final int windowWidth = 400;
private static final int windowHeight = 200;
private static final double SalesTax = 1.06;
private static JPanel panel;
private static JLabel lblPackages;
private static JLabel lblPhones;
private static JLabel lblOptions;
private static JLabel lblTotalls;
private static JLabel lblOutPutTotalls;
private static JComboBox cmbPackages;
private static JComboBox cmbCellPhones;
private static JList lstOptions;
private static String[] array = {
"8 gigabytes per month: 45.00 per"
+"month","16 gigabytes per month:65.00 per month"
+ "month", "20 gigabytes per"
+ "month: $99.00 per month"
};
private static String[] ArraySmartPhone =
{
"Model 100: $299.95",
"Model 110: $399.95",
"Model 200: $499.95"
};
private static String[] ArrayOptions =
{
"Phone Replacement Insurance: $5.00 per"
+ "month", "Wifi Hotspot Capability: $10.00 per month"
};
private DecimalFormat df = new DecimalFormat("#0.00");
private static double packageTotal;
private static double phoneTotal;
private static double optionTotal;
//Creating public constructor
public SmartPhonePackages()
{
//create a new window
JFrame window = new Jframe();
// Displaying the title
window.setTitle("Cell Phone Packages");
//Setting the size of the window
window.setTitle("Smart Phone Packages");
//Setting the size of the widnow
window.setSize(windowWidth, windowHeight);
//Close button
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Building the panel and adding it to the frame
buildpanel();
//Adding the panel to the frame's content
window.add(panel);
//displaying window
windows.setVisible(true);
}
private void buildPanel()
{
lblPackages = new JLabel ("Select package:");
lblPhones = new JLabel ("Select cell phone:");
lblOptions = new JLabel ("select your options");
lblTotals = new Jlabel ("total:");
lblOutputTotal = new JLabel();
//Creating combo boxes
cmbPackages = new JComboBOX(array);
cmbCellPhones = new JComboBox(ArraySmartPhone);
lstOptions = new JList(ArrayOptions);
lstOptions.setSelectionMode
(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
cmbPackages.AddActionListener (new packageListener());
cmbCellPhones.AddActionListener (new phoneListener());
lstOptions.AddListSelectionListener ( new
optionsListerner());
panel = new Jpanel();
//Adding the components to the objects
panel.setLayout(new GridLayout(4.2));
panel.add(lblPakcages);
panel.add(cmbPackages);
panel.add(lblPhones);
panel.add(cmbCellPhones);
panel.add(lblOptions);
panel.add(lstOptions);
panel.add(lblTotalls);
panel.add(lblOutputTotal);
}
public class packageListener implements
ActionListener
{
@Override
public void ActionPerformed(ActionEvent e)
{
//collecting the data
int packageSelected = cmbPackages.getSelectedIndex();
if (packageSelected == 0)
{
packageTotal = 45;
}
else if (packageSelected ==1)
{
packageTotal = 65;
}
else if(packageSelected ==2 )
{
packageTotal = 99;
}
//Displaying total
lblOutputTotal.setText("$" + df.format(optionTotal + packageTotal +
phoneTotal));
}
}
public class phoneListener implements
ActionListener
{
@override
public void actionPerformed(ActionEvent e)
{
int phoneSelected = cmbCellPhones.getSelectedIndex();
if (phoneSelected == 0)
{
phoneTotal = 299.95;
}
else if (phoneSelected == 1)
{
phoneTotal = 399.99;
}
else if (phoneSelected ==2)
{
phoneTotal = 499.95;
}
//calc sales tax
phoneTotal *= SalesTax;
//Displaying total
lblOutputTotal.setText("$" +df.format(optionTotal +
packageTotal
+phoneTotal));
}
}
public class optionsListener implements
ListSelectionListener { public void valueChanged
(ListSelectionEvent e)
{
double temp = 0;
int optionSelected[] = lstOpetions.getSelectedIndices();
for (int i = 0; i < optionSelected.length; i++)
{
if (optionSelected[i] == 0)
{
temp += 5;
}
if (optionSelected[i] == 1)
{
temp += 10;
}
}
optionTotal = temp;
lblOutputTotal.setText("$" + df.format(optionTotal + packageTotal +
phoneTotal));
}
}
}
public static void main(String[] args) {
launch(args);
}
}
Java code after removing errors:
============================================================================================
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@SuppressWarnings({"unchecked", "rawtypes"})
public class SmartPhonePackages extends JFrame
{
private static final long serialVersionID=
6548829860028144965L;
private static final int windowWidth = 800;
private static final int windowHeight = 200;
private static final double SalesTax = 1.06;
private static JPanel panel;
private static JLabel lblPackages;
private static JLabel lblPhones;
private static JLabel lblOptions;
private static JLabel lblTotalls;
private static JLabel lblOutPutTotalls;
private static JComboBox cmbPackages;
private static JComboBox cmbCellPhones;
private static JList lstOptions;
private static String[] array = {
"8 gigabytes per month: 45.00 per"
+"month","16 gigabytes per month:65.00 per month"
+ "month", "20 gigabytes per"
+ "month: $99.00 per month"
};
private static String[] ArraySmartPhone =
{
"Model 100: $299.95",
"Model 110: $399.95",
"Model 200: $499.95"
};
private static String[] ArrayOptions =
{
"Phone Replacement Insurance: $5.00 per"
+ "month", "Wifi Hotspot Capability: $10.00 per month"
};
private DecimalFormat df = new DecimalFormat("#0.00");
private static double packageTotal;
private static double phoneTotal;
private static double optionTotal;
//Creating public constructor
public SmartPhonePackages()
{
//create a new window
JFrame window = new JFrame();
// Displaying the title
window.setTitle("Cell Phone Packages");
//Setting the size of the window
window.setTitle("Smart Phone Packages");
//Setting the size of the widnow
window.setSize(windowWidth, windowHeight);
//Close button
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Building the panel and adding it to the frame
buildPanel();
//Adding the panel to the frame's content
window.add(panel);
//displaying window
window.setVisible(true);
}
private void buildPanel()
{
lblPackages = new JLabel ("Select package:");
lblPhones = new JLabel ("Select cell phone:");
lblOptions = new JLabel ("select your options");
lblTotalls = new JLabel ("total:");
lblOutPutTotalls = new JLabel();
//Creating combo boxes
cmbPackages = new JComboBox(array);
cmbCellPhones = new JComboBox(ArraySmartPhone);
lstOptions = new JList(ArrayOptions);
lstOptions.setSelectionMode
(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
cmbPackages.addActionListener (new packageListener());
cmbCellPhones.addActionListener (new phoneListener());
lstOptions.addListSelectionListener ( new optionsListener());
panel = new JPanel();
//Adding the components to the objects
panel.setLayout(new GridLayout());
panel.add(lblPackages);
panel.add(cmbPackages);
panel.add(lblPhones);
panel.add(cmbCellPhones);
panel.add(lblOptions);
panel.add(lstOptions);
panel.add(lblTotalls);
panel.add(lblOutPutTotalls);
}
public class packageListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
//collecting the data
int packageSelected = cmbPackages.getSelectedIndex();
if (packageSelected == 0)
{
packageTotal = 45;
}
else if (packageSelected ==1)
{
packageTotal = 65;
}
else if(packageSelected ==2 )
{
packageTotal = 99;
}
//Displaying total
lblOutPutTotalls.setText("$" + df.format(optionTotal +
packageTotal + phoneTotal));
}
}
public class phoneListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
int phoneSelected = cmbCellPhones.getSelectedIndex();
if (phoneSelected == 0)
{
phoneTotal = 299.95;
}
else if (phoneSelected == 1)
{
phoneTotal = 399.99;
}
else if (phoneSelected ==2)
{
phoneTotal = 499.95;
}
//calc sales tax
phoneTotal *= SalesTax;
//Displaying total
lblOutPutTotalls.setText("$" +df.format(optionTotal +
packageTotal
+phoneTotal));
}
}
public class optionsListener implements
ListSelectionListener
{
public void valueChanged (ListSelectionEvent e)
{
double temp = 0;
int optionSelected[] = lstOptions.getSelectedIndices();
for (int i = 0; i < optionSelected.length; i++)
{
if (optionSelected[i] == 0)
{
temp += 5;
}
if (optionSelected[i] == 1)
{
temp += 10;
}
}
optionTotal = temp;
lblOutPutTotalls.setText("$" + df.format(optionTotal + packageTotal
+ phoneTotal));
}
}
public static void main(String[] args) {
new SmartPhonePackages();
}
}
============================================================================================
Output

Can you please help me to run this Java program? I have no idea why it...
Why when executed my frame does not contain what i have added to it? Here is my code import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JPanel; @SuppressWarnings("serial") public class AddressBook1 extends JFrame implements ActionListener { /** * */ JLabel name = new JLabel("Name: "); JLabel address = new JLabel("Address: "); JLabel phone = new JLabel("Phone: "); JLabel email = new JLabel("Email: ");...
Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. public class FutureValueFrame extends JFrame { private JTextField investmentField; private JTextField interestRateField; private JComboBox yearsComboBox; private JList futureValueList; private DefaultListModel futureValueModel; public FutureValueFrame() { initComponents(); } private void initComponents() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.out.println(e); } setTitle("Future Value Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationByPlatform(true); investmentField = new JTextField(); interestRateField = new JTextField();...
I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...
I am getting this Error can you please fix my Java
code.
import java.awt.Dialog;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Fall_2017 {
public TextArea courseInput;
public Label textAreaLabel;
public JButton addData;
public Dialog confirmDialog;
HashMap<Integer, ArrayList<String>> students;
public Fall_2017(){
courseInput = new TextArea(20, 40);
textAreaLabel = new Label("Student's data:");
addData = new JButton("Add...
Can you fix my error? I created a program that changes labels every second in Java. But, it does not change. And, it will starts with second label. This is also an error. import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class Map2 extends JFrame{ JPanel panel; JLabel pic; Timer tm; int x = 0; String ly = "<html> " + "<br> <font size='10' color='red'> <b> 111111111 <b/> </font>...
In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...
Add a timer to the lightbulb ON/OFF program such that the bulb
stays on for 10 seconds after the ON button is pushed and then goes
off. Put a new label on the lightbulb panel that counts
the number of seconds the bulb is on and displays the number of
seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The
image above is what it should look like.
// Demonstrates mnemonics and tool tips.
//********************************************************************...
I got this programming its used to highlight text, but i couldn't remove highlight again from the text. i need someone to write me code that removes text highlight here is my code import java.awt.*; import java.awt.event.*; import java.util.Map; import java.util.HashMap; import javax.swing.*; import javax.swing.text.*; public class TextHighlight { private JTextArea textarea; private JComboBox colorbox; private JTextField top; private String[] colorOptions = { "GRAY", "YELLOW", "RED", "CYAN", "ORANGE", "PINK" }; private Highlighter.HighlightPainter grayPainter; private...
Need help debugging Create a GUI application that accepts student registration data. Specifications: The text box that displays the temporary password should be read-only. The temporary password consists of the user’s first name, an asterisk (*), and the user’s birth year. If the user enters data in the first three fields, display a temporary password in the appropriate text field and a welcome message in the label below the text fields. If the user does not enter data, clear the...
3.1 - In this exercise, you will see how to offer a user a selection among multiple choices. You can place all choices into a combo box using the following code: /** File HelloViewer.java */ import javax.swing.JFrame; public class HelloViewer { public static void main(String[] args) { JFrame frame = new HelloFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("HelloViewer"); frame.setVisible(true); } } ---------------------------- /** File HelloFrame.java */ import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.BorderLayout; import java.awt.Font; public class HelloFrame extends JFrame { private String message; private...