Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java runtime not working
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavan
Java runtime not working
1 Answer(s)      4 years and 11 months 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..

Advertisement
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


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
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
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 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
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
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
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 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
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
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
Java runtime example - JSP-Servlet
Java runtime example  in eclipse after submiting the data throgh jsp page i got the following error com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 1. the code is: Bean
JDBC:Runtime error - Java Beginners
JDBC:Runtime error  Dear sir/madam, thanks to respond for my request. I tried as you said but still i facing the same problem no suitable drivers found for mysql. I copied the mysql-connector-jave-5.0.8-bin.jar, mysql-connector
java runtime error: JDBC code - Java Beginners
java runtime error: JDBC code  Hi i want to insert data into mysql database in my local system. I installed mysql5.0 and using mm.mysql-2.0.4-bin.jar and also set in the class path. the code is compilled and giving runtime error
How to create a Java Runtime Editor - Swing AWT
How to create a Java Runtime Editor   Hi, I am working on a requirement in which I need to integrate a java runtime editor in swing application... using java swing, try the following code: import java.awt.BorderLayout
How to create Runtime time jLabel in java swing ?
How to create Runtime time jLabel in java swing ?   hi sir. my problem is that i want to display database row on a jLabel. Suppose i retrived... difficulties in creating jLabel at runtime according to user input. user
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
jsp runtime error - Java Server Faces Questions
jsp runtime error  how to lock and unlock the folder by using jsp programming
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
Java example to get Object class name at runtime
Java example to get Object class name at runtime       java get Object class name In java there is a way that makes us enabled to get the object class name at runtime. It can
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"> <
 

 

 

DMCA.com