Java runtime not working

Ads

 
 

Share on Google+Share on Google+

Ragavan
Java runtime not working
1 Answer(s)      7 years ago
Posted in : Java Beginners
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingFrame
{
public static void main(String[] args) throws Exception
{
SwingFrame1 sf=new SwingFrame1();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Age");
JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");
final JTextField txt=new JTextField(15);
JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JLabel lbl4=new JLabel("Branch");
final JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
lbl1.setBounds(100,120,70,30);
lbl2.setBounds(100,240,70,30);
lbl3.setBounds(100,340,70,30);
lbl4.setBounds(100,420,70,30);
jt1.setBounds(170,120,100,40);
jt2.setBounds(170,230,100,40);
Male.setBounds(170,340,100,40);
Female.setBounds(270,340,100,40);
jc.setBounds(170,420,100,40);
txt.setBounds(290,420,200,40);
jc.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
if(e.getSource() == jc) {
if(jc.getSelectedItem().equals("Others")){
txt.setVisible(true);
}
else{
txt.setVisible(false);
}

}
}
});
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(lbl4);
f.add(jt1);
f.add(jt2);
f.add(jc);
f.add(Male);
f.add(Female);
f.add(txt);
txt.setVisible(false);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
The above program not running please check it and reply..
Ads
View Answers

February 2, 2010 at 11:22 AM


Hi Friend,

You are calling constructor of another class in the main() method instead of SwingFrame() therefore you have got that error.Anyways, here is your code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingFrame
{
public static void main(String[] args) throws Exception
{
SwingFrame sf=new SwingFrame();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Age");
JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");
final JTextField txt=new JTextField(15);
JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JLabel lbl4=new JLabel("Branch");
final JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
lbl1.setBounds(100,120,70,30);
lbl2.setBounds(100,240,70,30);
lbl3.setBounds(100,340,70,30);
lbl4.setBounds(100,420,70,30);
jt1.setBounds(170,120,100,40);
jt2.setBounds(170,230,100,40);
Male.setBounds(170,340,100,40);
Female.setBounds(270,340,100,40);
jc.setBounds(170,420,100,40);
txt.setBounds(290,420,200,40);
jc.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
if(e.getSource() == jc) {
if(jc.getSelectedItem().equals("Others")){
txt.setVisible(true);
}
else{
txt.setVisible(false);
}

}
}
});
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(lbl4);
f.add(jt1);
f.add(jt2);
f.add(jc);
f.add(Male);
f.add(Female);
f.add(txt);
txt.setVisible(false);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
Java runtime not working - Java Beginners
Java runtime not working  import javax.swing.*; import java.awt.... SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane...("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1 = new
java runtime error - JDBC
java runtime error  when i m running my program using type1 driver it is showing a runtime error of SQLException of unable to create the connection object.please give the solution
Advertisements
Java Runtime
Java Runtime       In this section, you will learn about Java Runtime Environment (JRE), it also known as Java Runtime. This is a part of Java Development Kit (JDK). It is a set
java runtime error - JDBC
java runtime error  when i m running my program by using jdk1.6.0 then it is giving the error of classunsupported major.minor version 50.0.to remove it i installed jdk1.5 but now it is giving the classunsupported major.minor
runtime error in java
runtime error in java  What is Run time error in Java?   Run time error is a syntax error that during the execution of a program.It hash... the link, may this will be helpful for you. http://www.roseindia.net/java/java
java runtime error - JDBC
java runtime error  when i m running my jdbc program it is giving the problem as class not found exception.so, please suggest me what may be the solution regarding this.  Hi friend, The problem is of Jar
runtime error - Java Beginners
runtime error  I created a sample java source ,compiled it succesfully using command prompt but when i tried to run i got the folowing error " Exception in thread "main" java.lang.UnsupportedClassVersionError" I have set
Main topics in java for IT corporate working?
Main topics in java for IT corporate working?  What are the main and most important topics in java should be mastered that are usually incorporated in IT corporate world
java runtime error - JDBC
java runtime error  when i am running my jdbc program using thin driver this error is coming at runtime: Exception in thread "main... to this : Thrown when the Java Virtual Machine attempts to read a class file
java runtime error - JDBC
java runtime error  sir when i m running the jsp connectivity program it is giving the error as follows:' java.lang.NullPointerException at jsp_servlet.__resplogin._jspService(__resplogin.java:237
java runtime exception - JDBC
java runtime exception  while i executing this source code:- import java.sql.*; public class MysqlConnect { public static void main(String args[]) { System.out.println("MySQL Connect Example
java runtime error - Java Beginners
java runtime error  import java.io.*; class Test { public static....(on checking JVM from java.com, it says my JVM is working perfectly fine.) pls reply... and set the following: JAVA_HOME=C:\Program Files\Java\jdk1.6.0; Path=C
runtime error - Java Beginners
runtime error  sir run time error is coming again in this code also null pointer Exception at for( File f:contents) import java.io.*; public class RecentDocumentsDelete { public static void main(String[] args) { String
java runtime error - Java Beginners
java runtime error  sir, i have installed jdk in my system.i had also set path.But i am unable to run the compiled class file.it shows run time...://www.roseindia.net/java/java-classpath.shtml Thanks
java runtime error
java runtime error  hi friends i am trying to run the fallowing program but i am getting the error Exception in thread "main" java.lang.UnsupportedClassVersionError: JDBCCreateTab le (Unsupported major.minor version 50.0
Get current working directory in Java
Get current working directory in Java In this section we will discuss about how to get the the current working directory in java. Current working directory means the current working directory where java program execute. In java
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page
runtime error - Java Beginners
runtime error  import java.io.*; public class RecentDocumentsDelete { public static void main(String[] args) { String currentUser = System.getProperty("user.name"); System.out.println(currentUser
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
How to get UTF-8 working in java webapps?
How to get UTF-8 working in java webapps?  How to get UTF-8 working in java webapps
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page-- > <html:form action
Java Runtime error - Java Beginners
Java Runtime error  I have designed a simple chat application where the client and the server is the same computer itself. I have used the ipaddress of my computer and then designed a GUI application to interact between the two
java runtime error - Development process
java runtime error  I Migrated jdk1.3 to jdk1.4. after that my ftp clint not working.iam getting class not found exception fileinputstreem. i am using sun package. can any one send pure java code for FTP process i think jdk
working wit string - Java Beginners
working wit string  accept a paragraph of text. consisting of sentences that are terminated by either '.' or '?' or '!' followed by a single space. assume that there can be maximum of five sentences in a paragraph. design
Version of com.kaaprotech>satu-runtime-java dependency
List of Version of com.kaaprotech>satu-runtime-java dependency
JDBC:Runtime error - Java Beginners
JDBC:Runtime error  Dear sir/madam i am facing a problem with jdbc program. When i run my program using NetBeans6.1 it is working fine. When i try to run the program from command prompt it is giving error. The follwing
why jsp pages are not working on linux but java application is working in windows - JSP-Servlet
why jsp pages are not working on linux but java application is working in windows  java web application jsp pages are not showing the fileds corectly on linux server but same application is working on windows.why
Java runtime error - JSP-Servlet
Java runtime error  Following Error is showing when i way scanner.acquire() can any body help me please uk.co.mmscomputing.device.sane.SaneIOException: uk.co.mmscomputing.device.sane.SaneDeviceManager.getDevice
Error during runtime NoClassDefFound in java
Error during runtime NoClassDefFound in java  code: package Jama...; /** Working storage for nonsymmetric algorithm. @serial working storage...[n-1][n-1] - H[n][n]) / 2.0; q = p * p + w; z
Error during runtime NoClassDefFound in java
Error during runtime NoClassDefFound in java  code: package Jama...; /** Working storage for nonsymmetric algorithm. @serial working storage...[n-1][n-1] - H[n][n]) / 2.0; q = p * p + w; z