Reputation: 1
I'm trying to create a frame with two buttons Submit and Cancel. I'm new to java and can't get this to run. I've tried a few different approaches and I can't get absolutely anything to run.
import javax.swing.*;
public static void main(String[] args){
JFrame frame=new JFrame("Select One";)
//add a button
JButton jbtSubmit=new JButton ("Submit");{
frame.add(JbtSubmit);
JButton jbtCancel=new JButton ("Cancel");{
frame.add(JbtCancel);
frame.setsize(300,400);// sets frame size
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().add(emptyLabel, BorderLayout.CENTER)//components to put in frame
frame.sertLocationRelativeTo(null);//Centers frame
frame.setVisable(true);//display the frame
}
}
my errors
Description Resource Path Location Type
Syntax error on tokens, delete these tokens yButton.java /ICS141/src line 3 Java Problem
Syntax error on token "JFrame", ( expected after this token yButton.java /ICS141/src line 3 Java Problem
Syntax error, insert ")" to complete Arguments yButton.java /ICS141/src line 5 Java Problem
Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. ICS141 Build path JRE System Library Problem
Syntax error, insert ")" to complete ClassInstanceCreationExpression yButton.java /ICS141/src line 5 Java Problem
Syntax error, insert "]" to complete ArrayAccess yButton.java /ICS141/src line 2 Java Problem
Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. two Build path JRE System Library Problem
Syntax error on token "]", invalid ( yButton.java /ICS141/src line 2 Java Problem
Syntax error, insert "enum Identifier" to complete EnumHeader yButton.java /ICS141/src line 2 Java Problem
Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. Eclipse Build path JRE System Library Problem
Syntax error, insert ")" to complete SingleMemberAnnotation yButton.java /ICS141/src line 2 Java Problem
Syntax error on tokens, AnnotationName expected instead yButton.java /ICS141/src line 2 Java Problem
Upvotes: 0
Views: 87
Reputation: 18812
See comments for changes I made in your code :
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
//added class deceleration : see @MadProgrammer comment
public class Test {
public static void main(String[] args){
JFrame frame= new JFrame("Select One"); //moved ;
frame.getContentPane().setLayout(new FlowLayout());//added layout manager
//add a button
JButton jbtSubmit=new JButton ("Submit"); //removed {
frame.getContentPane().add(jbtSubmit);
JButton jbtCancel= new JButton ("Cancel");//removed {
frame.getContentPane().add(jbtCancel); //changed JbtCancel to
frame.setPreferredSize(new Dimension(300,400)) ;// changed to setPreferredSize
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().add(emptyLabel, BorderLayout.CENTER)//components to put in frame
frame.setLocationRelativeTo(null);// changed sertLocationRelativeTo(null) to setLocationRelativeTo
frame.pack(); //added
frame.setVisible(true);//changed setVisable tp setVisible
}
}
Upvotes: 1
Reputation: 419
Java is an Object Oriented Language.You are trying to do your program on procedure oriented way.I think you must start from the basic hello world
Upvotes: 0