
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 Data");
addData.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
confirmDialog.show();
}
});
createGUI();
}
public void createGUI(){
JFrame frame = new JFrame("Student's Data");
frame.setVisible(true);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.add(textAreaLabel);
panel.add(courseInput);
panel.add(addData);
frame.getContentPane().add(panel);
initialiseConfirmDialog(frame);
}
private void initialiseConfirmDialog(JFrame frame) {
confirmDialog = new Dialog(frame);
JPanel panel = new JPanel();
panel.add(new Label("Do you want to add more students?"));
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
yesButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
confirmDialog.hide();
}
});
noButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
confirmDialog.hide();
String text = courseInput.getText();
processCourse(text);
courseInput.setText("");
}
} );
panel.add(yesButton);
panel.add(noButton);
confirmDialog.add(panel);
confirmDialog.setSize(200, 100);
}
private void processCourse(String text) {
students = new HashMap<>();
for(String studentData:text.split("\n")){
String[] data = studentData.split(" ");
if(students.containsKey(Integer.parseInt(data[0]))){
students.get(Integer.parseInt(data[0])).add(data[1]);
}else{
ArrayList<String> courses = new ArrayList<>();
courses.add(data[1]);
students.put(Integer.parseInt(data[0]), courses);
}
}
for(Entry<Integer,ArrayList<String>>
entry:students.entrySet()){
System.out.println(entry.getKey());
System.out.println(entry.getValue());
System.out.println();
}
}
public static void main(String[] args) {
Fall_2017 gui = new Fall_2017();
}
}
This is not an error , its a warning message.
recompiler with the below syntax
javac -Xlint xzy.java //provide java file name
you can also try below option. javac -Xlint:deprecation xyz.java
I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...
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>...
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: ");...
With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...
I have currently a functional Java progam with a gui. Its a
simple table of contacts with 3 buttons: add, remove, and edit.
Right now the buttons are in the program but they do not work yet.
I need the buttons to actually be able to add, remove, or edit
things on the table. Thanks so much.
Here is the working code so far:
//PersonTableModel.java
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class PersonTableModel extends AbstractTableModel
{
private static final int...
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************************************...
Re-write this program into a javafx program, using javafx components only. NO awt or swing. import java.awt.Button; import java.awt.Label; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; public class DecimalBinary { public static void main(String[] args) { JFrame frame=new JFrame(); //Create a frame frame.setTitle("Decimal-Binary Converter"); //Set its label frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); //Set size fo frame JPanel panel=new JPanel(); //Create a panel to contain controls frame.add(panel); //add panel to frame panel.setLayout(null); Label decimalLabel=new Label("Decimal"); //Create label for decimal decimalLabel.setBounds(10,...
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...
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...
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.
//********************************************************************...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
public class Q1 extends JFrame {
public static void createAndShowGUI() {
JFrame frame = new
JFrame("Q1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Font courierFont = new
Font("Courier", Font.BOLD, 40);
Font arialFont = new Font("Arial",
Font.BOLD, 40);
Font sansFont = new
Font("Sans-serif", Font.BOLD, 20);
JLabel label = new JLabel("Enter a
word"); label.setFont(sansFont);
Font font1 = new Font("Sans-serif",
Font.BOLD, 40);
...