SlideShare a Scribd company logo
I am getting a syntax error. I can't seem to find what's causing this progrm even though I correct
what it's asking me to do. It seems to add even more errors.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class GUI extends JFrame {
// create required GUI radios, labels, textfields and buttons
private JRadioButton iterative;
private JRadioButton recursive;
private JLabel entern;
private JLabel result;
private JLabel efficiency;
private JTextField t1;
private JTextField t2;
private JTextField t3;
private JButton compute;
private ButtonGroup radios = new ButtonGroup();
private ButtonGroup candidates = new ButtonGroup();
// create constructor for GUI
public GUI(){
super("Project 3");
setLayout (new GridLayout(6,2));
setSize(275,250);
// initializing buttons and etc and adding them
iterative = new JRadioButton("Iterative");
add(iterative);
recursive = new JRadioButton("Recursive");
add(recursive);
// add radiobuttons to group so only one selection is possible
radios.add(iterative);
radios.add(recursive);
entern = new JLabel("Enter n:");
add(entern);
result = new JLabel("Result:");
add(result);
efficiency = new JLabel("Efficiency:");
add(efficiency);
t1 = new JTextField();
add(t1);
compute = new JButton("Compute");
add(compute);
t2 = new JTextField();
add(t2);
t3 = new JTextField();
add(t3);
/*
thehandler handler = new thehandler();
iterative.addActionListener(handler);
recursive.addActionListener(handler);
compute.addActionListener(handler);
****************************/
compute.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent b){
computeactionPerformed(b);
private void computeactionPerformed(ActionEvent b){
if ((iterative.isSelected(true))){
JOptionPane.showMessageDialog(null,"you chose iterative");
}
else if (recursive.isSelected(true)){
JOptionPane.showMessageDialog(null,"you chose recursive");
}
}
}
});
// create sub-panel for radio buttons
JPanel radioPanel = new JPanel();
radioPanel.add(iterative);
radioPanel.add(recursive);
/*
class thehandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==iterative && e.getSource()==compute){
System.out.println("you chose iterative");
}
else if(e.getSource()==recursive && e.getSource()==compute){
System.out.println("you chose recursive");
}
}
}
******************************/
}
public static void main(String[]args){
GUI object = new GUI();
object.setVisible(true);
object.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Solution
I have Change in code . No it's working without any compliantion error.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class GUI extends JFrame {
// create required GUI radios, labels, textfields and buttons
private JRadioButton iterative;
private JRadioButton recursive;
private JLabel entern;
private JLabel result;
private JLabel efficiency;
private JTextField t1;
private JTextField t2;
private JTextField t3;
private JButton compute;
private ButtonGroup radios = new ButtonGroup();
private ButtonGroup candidates = new ButtonGroup();
// create constructor for GUI
public GUI()
{
super("Project 3");
setLayout (new GridLayout(6,2));
setSize(275,250);
// initializing buttons and etc and adding them
iterative = new JRadioButton("Iterative");
add(iterative);
recursive = new JRadioButton("Recursive");
add(recursive);
// add radiobuttons to group so only one selection is possible
radios.add(iterative);
radios.add(recursive);
entern = new JLabel("Enter n:");
add(entern);
result = new JLabel("Result:");
add(result);
efficiency = new JLabel("Efficiency:");
add(efficiency);
t1 = new JTextField();
add(t1);
t2 = new JTextField();
add(t2);
t3 = new JTextField();
add(t3);
compute = new JButton("Compute");
add(compute);
compute.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent b)
{
if (iterative.isSelected())
{
JOptionPane.showMessageDialog(null,"you chose iterative");
}
else if (recursive.isSelected())
{
JOptionPane.showMessageDialog(null,"you chose recursive");
}
}
});
// create sub-panel for radio buttons
JPanel radioPanel = new JPanel();
radioPanel.add(iterative);
radioPanel.add(recursive);
}
public static void main(String[]args){
GUI object = new GUI();
object.setVisible(true);
object.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

More Related Content

Similar to I am getting a syntax error. I cant seem to find whats causing t.pdf (20)

PDF
Write a GUI application to simulate writing out a check. The value o.pdf
fathimaoptical
 
PPT
Java awt
GaneshKumarKanthiah
 
PDF
In Java Write a GUI application to simulate writing out a check. The.pdf
flashfashioncasualwe
 
PDF
correct the error and add code same in the pic import jav.pdf
devangmittal4
 
PDF
import javaxswing import javaawtevent import javai.pdf
ADITIEYEWEAR
 
PDF
How do I make my JTable non editableimport java.awt.; import j.pdf
forwardcom41
 
PDF
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
PDF
pbl oops complete-1-merged (1).p chd chd cdf
rashikapoor192005
 
PDF
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
sudhirchourasia86
 
TXT
Maze
yito24
 
PDF
package buttongui; import static com.sun.deploy.config.JREInf.pdf
arjuntiwari586
 
PDF
Calculon
Matthias Käppler
 
PPT
What do you mean it needs to be Java based? How jython saved the day.
Mark Rees
 
PDF
Chat application in java using swing and socket programming.
Kuldeep Jain
 
DOCX
Exercícios Netbeans - Vera Cymbron
cymbron
 
PDF
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
badshetoms
 
DOCX
New microsoft office word document
nidhileena
 
PDF
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
DOCX
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
Write a GUI application to simulate writing out a check. The value o.pdf
fathimaoptical
 
In Java Write a GUI application to simulate writing out a check. The.pdf
flashfashioncasualwe
 
correct the error and add code same in the pic import jav.pdf
devangmittal4
 
import javaxswing import javaawtevent import javai.pdf
ADITIEYEWEAR
 
How do I make my JTable non editableimport java.awt.; import j.pdf
forwardcom41
 
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
pbl oops complete-1-merged (1).p chd chd cdf
rashikapoor192005
 
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
sudhirchourasia86
 
Maze
yito24
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
arjuntiwari586
 
What do you mean it needs to be Java based? How jython saved the day.
Mark Rees
 
Chat application in java using swing and socket programming.
Kuldeep Jain
 
Exercícios Netbeans - Vera Cymbron
cymbron
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
badshetoms
 
New microsoft office word document
nidhileena
 
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 

More from fashionfolionr (20)

PDF
Discuss the benefits of in-built coding software within the Health I.pdf
fashionfolionr
 
PDF
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
fashionfolionr
 
PDF
According to the Fick equation, what happens to J when X (the distanc.pdf
fashionfolionr
 
PDF
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
fashionfolionr
 
PDF
Briefly discuss operating system, firmware, and utility programs..pdf
fashionfolionr
 
PDF
Assume that scores on the LSAT are approximately normally distribute.pdf
fashionfolionr
 
PDF
A polynomial may be represented as a linked list where each node cont.pdf
fashionfolionr
 
PDF
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
fashionfolionr
 
PDF
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
fashionfolionr
 
PDF
Write a function prototype for each of the following functions (Jus.pdf
fashionfolionr
 
PDF
Why is white collar crime is so difficult to address with law enforc.pdf
fashionfolionr
 
PDF
What is Eulers number and who is it named after Can you name some.pdf
fashionfolionr
 
PDF
Using C++...Hints- Use binary file readwrite to store employee .pdf
fashionfolionr
 
PDF
Unless specifically legally permitted, agreements to suppress or eli.pdf
fashionfolionr
 
PDF
There are tremendous pressures on selected industrialized countries,.pdf
fashionfolionr
 
PDF
This week we covered Accounting and Payroll liabilities and the diff.pdf
fashionfolionr
 
PDF
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
fashionfolionr
 
PDF
Stark Company has five employees. Employees paid by the hour receive.pdf
fashionfolionr
 
PDF
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
fashionfolionr
 
PDF
Q1 Discuss three types of accounting anomalies and define why they .pdf
fashionfolionr
 
Discuss the benefits of in-built coding software within the Health I.pdf
fashionfolionr
 
Determine if each system is1. memoryless2. Invertible3. Causal.pdf
fashionfolionr
 
According to the Fick equation, what happens to J when X (the distanc.pdf
fashionfolionr
 
A 14 foot ladder is leaning against a building. If the bottom of the.pdf
fashionfolionr
 
Briefly discuss operating system, firmware, and utility programs..pdf
fashionfolionr
 
Assume that scores on the LSAT are approximately normally distribute.pdf
fashionfolionr
 
A polynomial may be represented as a linked list where each node cont.pdf
fashionfolionr
 
All answers must be in your own wordsWhat iswas The Great Law Wh.pdf
fashionfolionr
 
4. An upward shift in the Reserve Bank of Australias policy reactio.pdf
fashionfolionr
 
Write a function prototype for each of the following functions (Jus.pdf
fashionfolionr
 
Why is white collar crime is so difficult to address with law enforc.pdf
fashionfolionr
 
What is Eulers number and who is it named after Can you name some.pdf
fashionfolionr
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
fashionfolionr
 
Unless specifically legally permitted, agreements to suppress or eli.pdf
fashionfolionr
 
There are tremendous pressures on selected industrialized countries,.pdf
fashionfolionr
 
This week we covered Accounting and Payroll liabilities and the diff.pdf
fashionfolionr
 
t Assignment 2 Econ 201 Importance of scarcity. SolutionScarc.pdf
fashionfolionr
 
Stark Company has five employees. Employees paid by the hour receive.pdf
fashionfolionr
 
Silas, Cole, and Addison are on the same Learning Team at UOP. If ea.pdf
fashionfolionr
 
Q1 Discuss three types of accounting anomalies and define why they .pdf
fashionfolionr
 

Recently uploaded (20)

PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
John Keats introduction and list of his important works
vatsalacpr
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 

I am getting a syntax error. I cant seem to find whats causing t.pdf

  • 1. I am getting a syntax error. I can't seem to find what's causing this progrm even though I correct what it's asking me to do. It seems to add even more errors. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; public class GUI extends JFrame { // create required GUI radios, labels, textfields and buttons private JRadioButton iterative; private JRadioButton recursive; private JLabel entern; private JLabel result; private JLabel efficiency; private JTextField t1; private JTextField t2; private JTextField t3; private JButton compute; private ButtonGroup radios = new ButtonGroup(); private ButtonGroup candidates = new ButtonGroup(); // create constructor for GUI public GUI(){ super("Project 3"); setLayout (new GridLayout(6,2)); setSize(275,250); // initializing buttons and etc and adding them iterative = new JRadioButton("Iterative");
  • 2. add(iterative); recursive = new JRadioButton("Recursive"); add(recursive); // add radiobuttons to group so only one selection is possible radios.add(iterative); radios.add(recursive); entern = new JLabel("Enter n:"); add(entern); result = new JLabel("Result:"); add(result); efficiency = new JLabel("Efficiency:"); add(efficiency); t1 = new JTextField(); add(t1); compute = new JButton("Compute"); add(compute); t2 = new JTextField(); add(t2); t3 = new JTextField(); add(t3); /* thehandler handler = new thehandler(); iterative.addActionListener(handler); recursive.addActionListener(handler); compute.addActionListener(handler); ****************************/ compute.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent b){ computeactionPerformed(b); private void computeactionPerformed(ActionEvent b){ if ((iterative.isSelected(true))){ JOptionPane.showMessageDialog(null,"you chose iterative"); } else if (recursive.isSelected(true)){
  • 3. JOptionPane.showMessageDialog(null,"you chose recursive"); } } } }); // create sub-panel for radio buttons JPanel radioPanel = new JPanel(); radioPanel.add(iterative); radioPanel.add(recursive); /* class thehandler implements ActionListener{ public void actionPerformed(ActionEvent e) { if(e.getSource()==iterative && e.getSource()==compute){ System.out.println("you chose iterative"); } else if(e.getSource()==recursive && e.getSource()==compute){ System.out.println("you chose recursive"); } } } ******************************/ } public static void main(String[]args){ GUI object = new GUI(); object.setVisible(true); object.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
  • 4. } Solution I have Change in code . No it's working without any compliantion error. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; public class GUI extends JFrame { // create required GUI radios, labels, textfields and buttons private JRadioButton iterative; private JRadioButton recursive; private JLabel entern; private JLabel result; private JLabel efficiency; private JTextField t1; private JTextField t2; private JTextField t3; private JButton compute; private ButtonGroup radios = new ButtonGroup(); private ButtonGroup candidates = new ButtonGroup(); // create constructor for GUI public GUI() { super("Project 3"); setLayout (new GridLayout(6,2)); setSize(275,250);
  • 5. // initializing buttons and etc and adding them iterative = new JRadioButton("Iterative"); add(iterative); recursive = new JRadioButton("Recursive"); add(recursive); // add radiobuttons to group so only one selection is possible radios.add(iterative); radios.add(recursive); entern = new JLabel("Enter n:"); add(entern); result = new JLabel("Result:"); add(result); efficiency = new JLabel("Efficiency:"); add(efficiency); t1 = new JTextField(); add(t1); t2 = new JTextField(); add(t2); t3 = new JTextField(); add(t3); compute = new JButton("Compute"); add(compute); compute.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent b) { if (iterative.isSelected()) { JOptionPane.showMessageDialog(null,"you chose iterative"); } else if (recursive.isSelected())
  • 6. { JOptionPane.showMessageDialog(null,"you chose recursive"); } } }); // create sub-panel for radio buttons JPanel radioPanel = new JPanel(); radioPanel.add(iterative); radioPanel.add(recursive); } public static void main(String[]args){ GUI object = new GUI(); object.setVisible(true); object.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }