473,653 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems compiling a swing program

44 New Member
hi friends i'm not able to debug this code please tell me wht is wrong here...


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.swing.*;
  4. class test extends JFrame implements ActionListener
  5. {
  6.  
  7.     JButton b1;
  8.     JTextField Tf1;
  9.     public test()
  10.     {
  11.         b1=new JButton("1");
  12.         Tf1=new TextField(10);
  13.  
  14.         setLayout(new Frlowlayout());
  15.  
  16.         add(b1);
  17.         add(Tf1);
  18.  
  19.         addActionListener(this);
  20.  
  21.         setSize(200,200);
  22.         setVisible(true);
  23.  
  24.     }
  25.     public void actionPerformed(ActionEvent e)
  26.     if (e.getSource() == b1)
  27.     {
  28.         Tf1.setText("1");
  29.     }
  30.     public static void main(String args[])
  31.     {
  32.         test t=new test();
  33.     }
  34. }
Aug 29 '07 #1
14 1440
Nepomuk
3,112 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.     import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*; // Correction 1
  4.       class test extends JFrame implements ActionListener
  5.       {
  6.  
  7.           JButton b1;
  8.           JTextField Tf1;
  9.           public test()
  10.           {
  11.               b1=new JButton("1");
  12.               Tf1=new JTextField(10); // Correction 2
  13.  
  14.               setLayout(new Frlowlayout()); // What should that be?
  15.  
  16.               add(b1);
  17.               add(Tf1);
  18.  
  19.               addActionListener(this); // This IS an ActionListener - why do you want to add one?
  20.  
  21.               setSize(200,200);
  22.               setVisible(true);
  23.  
  24.           }
  25.           public void actionPerformed(ActionEvent e) // Correction 3
  26.           {
  27.               if (e.getSource() == b1)
  28.               {
  29.                   Tf1.setText("1");
  30.               }
  31.           }
  32.           public static void main(String args[])
  33.           {
  34.               test t=new test();
  35.           }
  36.       }
  37.  
Aug 29 '07 #2
r035198x
13,262 MVP
hi friends i'm not able to debug this code please tell me wht is wrong here...


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.swing.*;
  4. class test extends JFrame implements ActionListener
  5. {
  6.  
  7.     JButton b1;
  8.     JTextField Tf1;
  9.     public test()
  10.     {
  11.         b1=new JButton("1");
  12.         Tf1=new TextField(10);
  13.  
  14.         setLayout(new Frlowlayout());
  15.  
  16.         add(b1);
  17.         add(Tf1);
  18.  
  19.         addActionListener(this);
  20.  
  21.         setSize(200,200);
  22.         setVisible(true);
  23.  
  24.     }
  25.     public void actionPerformed(ActionEvent e)
  26.     if (e.getSource() == b1)
  27.     {
  28.         Tf1.setText("1");
  29.     }
  30.     public static void main(String args[])
  31.     {
  32.         test t=new test();
  33.     }
  34. }
Frlowlayout should have been FloorLayout?
Aug 29 '07 #3
Nepomuk
3,112 Recognized Expert Specialist
Frlowlayout should have been FloorLayout?
Probably FlowLayout. ^^
Aug 29 '07 #4
praveen2gupta
201 New Member
Hi
Line setLayout(new Frlowlayout());
is wrong It should be written as
setLayout(new Flowlayout());
Rest is o.k.
Aug 29 '07 #5
r035198x
13,262 MVP
Frlowlayout should have been FloorLayout?
Oh yeah, thanks.
Aug 29 '07 #6
JosAH
11,448 Recognized Expert MVP
Do not add JComponents to a JFrame directly. Get the JFrame's content pane
(see the API docs) and add your components to that pane instead.

kind regards,

Jos
Aug 29 '07 #7
mak1084
44 New Member
[PHP]import java.awt.*;
import java.awt.event. *;
import javax.swing.*;
class test extends JFrame implements ActionListener
{

JButton b1;
JTextField Tf1;
public test()
{
b1=new JButton("1");
Tf1=new JTextField(10);

setLayout(new Flowlayout());

add(b1);
add(Tf1);

addActionListen er(this);

setSize(200,200 );
setVisible(true );

}
public void actionPerformed (ActionEvent e)
if (e.getSource() == b1)
{
Tf1.setText("1" );
}
public static void main(String args[])
{
test t=new test();
}
}[/PHP]

after compiling geting this error...

Expand|Select|Wrap|Line Numbers
  1. C:\test.java:26: ';' expected
  2.     if (e.getSource() == b1)
Aug 29 '07 #8
JosAH
11,448 Recognized Expert MVP
[PHP]import java.awt.*;
import java.awt.event. *;
import javax.swing.*;
class test extends JFrame implements ActionListener
{

JButton b1;
JTextField Tf1;
public test()
{
b1=new JButton("1");
Tf1=new JTextField(10);

setLayout(new Flowlayout());

add(b1);
add(Tf1);

addActionListen er(this);

setSize(200,200 );
setVisible(true );

}
public void actionPerformed (ActionEvent e)
if (e.getSource() == b1)
{
Tf1.setText("1" );
}
public static void main(String args[])
{
test t=new test();
}
}[/PHP]

after compiling geting this error...

Expand|Select|Wrap|Line Numbers
  1. C:\test.java:26: ';' expected
  2.     if (e.getSource() == b1)
See how you defined your, eg, main method; spot the diferences from your
actionPerformed method (don't mention 'static').

kind regards,

Jos
Aug 29 '07 #9
mak1084
44 New Member
See how you defined your, eg, main method; spot the diferences from your
actionPerformed method (don't mention 'static').

kind regards,

Jos
Not geting wht u want to say i'm novice in java....
Aug 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6415
by: Joseph | last post by:
hi 1) i plan on having an awt canvas component (to draw graphs) on a JFrame with other swing components..will this be okay? i've read that swing and awt aren't compatible.. 2)Also, if i have a function which simply loops infinately that is part of a form, what happens when a form event (eg button click) occurs? will the event handler be executed simulatanesouly with the loop? or does the event excecute first and then the loop is...
3
2495
by: Ted Byers | last post by:
This is quite frustrating! In the documents, and in the newsgroups, I see simple instructions like the following: =============================================== ==========Beginning of Ray's example================= =============================================== Suppose you want to run class com.xyz.Main. Then create a manifest file like this: ======== main.mf starts on the next line ====
10
3675
by: stu7 | last post by:
+ I have some problems with QT. I know that it is supposed to be useful for compiling cross-platform versions of a program, and that it has something to do with C++ ...not a problem so far. But - if QT compilies a program for Linux (my interest)... why do I have to install QT (again) to use it ? It seems it hasn't compiled -FOR- Linux at all, but is only using the Linux framework to run itself on_ acting more like a virus than a...
0
1355
by: Rob Heersma | last post by:
Hello, A couple of days I am trying to install Protege on my computer together with the owl plugin. But perpetually I receive the same understanding attached problem. I have installed Protege 2.0 beta build 119 as well as build 121. For the Java virual machine I used j2sdk1.4.2_03. Do You have any notice of what the problem could me? Kinds regards, Rob Urlings
0
2246
by: Suzie | last post by:
Hello, I'm only new at this so please bear with me! I am creating an ontology for a color game and i am using the pizza tutorial as a basis for it. I did everything and when I went to save the file I get a message saying save project errors with these error messages: java.lang.RuntimeException: horrible http://www.owl-ontologies.com/unnamed.owl#0000 at com.hp.hpl.jena.shared.impl.PrefixMappingImpl.checkProper
2
2114
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before my other includes then I get lots of errors like C2011: 'fd_set' : 'struct' type redefinition warning C4005: 'FD_CLR' : macro redefinition which I understand are due to the fact that windows.h is being included in another header file as well as...
21
2934
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
8
1673
by: carlos123 | last post by:
hello, i am making a hall pass program for my computer programming class. i am having issues with my jcheckboxes. first off. this file reads from a .txt that just has greg john joe 54343 45777 33444 in it. after the user puts in a correct id number, it displays 4 checkboxes to where they want to go. bathroom, office, nurse, and other. once the user clicks one of the checkboxes, it will remove all the stuff from the panel, and add the...
8
5677
risk32
by: risk32 | last post by:
Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box : int reply; String message = "Do you want to input another number?"; String title = "Input Another Number?"; reply = (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.NO_OPTION) { System.exit(0); } This part works great, now down to business:
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.