Swing Programming Question
Hi, and thanks for reading this.
I have a simple Swing application. When launching the application, it displays a "JFrame" that contains a "JButton". When activating the "JButton", a custom "JDialog" is opened. The custom "JDialog" is a class that I wrote that extends "JDialog". The constructor for this custom "JDialog" builds the dialog and displays it. Currently, the "actionPerformed()" method (of the "JButton", in the "JFrame") invokes the custom "JDialog"'s constructor (no, not every time, but the constructor has to be called sometime, right?). My question is, should the constructor invocation be wrapped in a "SwingUtilities.invokeLater()" or "SwingUtilities.invokeAndWait()", or not?
Thanks (in advance),
Avi.
It's not necessary. actionPerformed() is invoked by the event dispatch thread in reaction to a mouse event, so it's safe for any gui manipulation code to be placed in that method.
Similar Messages
-
Error while running Swing program on FreeBSD
Hi,
I am trying to run simple swing program "helloworld"
but while executing it gives following error on FreeBSD
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/usr/local/linux-sun-jdk1.4.2/jre/lib/i386/libawt.so: libXp.so.6:
cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1477)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)
at sun.awt.DebugHelper.<clinit>(DebugHelper.java:29)
at java.awt.EventQueue.<clinit>(EventQueue.java:80)
at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1170)
at JPanels.main(JPanels.java:29)
Should i install XFree86-libs package on FreeBsd
configuration
FreeBSD 4.10-BETA (GENERIC)
I am using following packages
linux-sun-jdk-1.4.2.04 Sun Java Development Kit 1.4 for Linux
linux_base-8-8.0_4 Base set of packages needed in Linux mode (only for i386)
linux_devtools-8.0_1 Packages needed for doing development in Linux mode
libtool-1.3.5_1 Generic shared library support script
gmake-3.80_1 GNU version of 'make' utility
automake-1.4.5_9 GNU Standards-compliant Makefile generator (legacy version
GCC 2.95.4
gdb 4.18
ld 2.12.1 supported emulation elf_i386
regards
Man479This is not really a Swing question. You should install the library which satisfies the lookup of libXp.so.6 .
I quess the jre for this platform is compiled against this version. Looks to me like some X related library, maybe google can resolve a solution/package to install?
Greetz -
Keyboard-lock of swing program on Linux box
We are developing swing program on Linux, and we often meet keyboard-lock issues.
I try to simplify some of them to small programs, and still meet keyboard-lock.
Here I post two programs to show the error:
//---first ----------------------------------------------
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class KeyLock extends JFrame {
JPanel contentPanel = new JPanel();
JPanel wizardToolPan = new JPanel();
JButton btnBack = new JButton("Back");
JButton btnNext = new JButton("Next");
JButton btnAbout = new JButton("About");
public static final String aboutMsg =
"<html> This program will help to find keyboard lock problems, two way to reproduce:<br><br>" +
"1 - press Alt+N to navigate next, and don't release keys untill there are no more next page, <br>" +
"then try Alt+B to navigate back and also don't release keys untill page 0,<br>" +
"repeat Alt+N and Alt+B again and again, keyboard will be locked during navigating. <br><br>" +
"2 - press Alt+A in main window, it will popup an about dialog,<br>" +
"then press down space key and don't release, <br>" +
"the about dialog will be closed and opened again and again,<br>" +
"keyboard will be locked sooner or later." +
"</html>";
public KeyLock() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("Keyboard lock test");
getContentPane().setLayout(new BorderLayout());
btnBack.setMnemonic('B');
btnBack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
KeyLock.this.goBack(e);
btnNext.setMnemonic('N');
btnNext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
KeyLock.this.goNext(e);
btnAbout.setMnemonic('A');
btnAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(KeyLock.this, aboutMsg, "About", JOptionPane.INFORMATION_MESSAGE);
contentPanel.setLayout(new BorderLayout());
contentPanel.setPreferredSize(new Dimension(400, 250));
contentPanel.setMinimumSize(new Dimension(400, 250));
wizardToolPan.setLayout(new FlowLayout());
wizardToolPan.add(btnBack);
wizardToolPan.add(btnNext);
wizardToolPan.add(btnAbout);
this.getContentPane().add(contentPanel, java.awt.BorderLayout.CENTER);
this.getContentPane().add(wizardToolPan, java.awt.BorderLayout.SOUTH);
this.setSize(400, 300);
this.createContentPanels();
this.showCurrent();
private Vector<JPanel> slides = new Vector<JPanel>();
private int current = 0;
private void createContentPanels() {
for (int j = 0; j < 20; ++j) {
JPanel p = new JPanel(new FlowLayout());
p.add(new JLabel("Page: " + j));
p.add(new JTextField("Page: " + j + ", input something here", 20));
p.add(new JTextField("Page: " + j + ", input something here", 20));
p.add(new JTextField("Page: " + j + ", input something here", 20));
p.add(new JLabel("Input something in password box:"));
p.add(new JPasswordField(20));
p.add(new JCheckBox("Try click here, focus will be here."));
p.add(new JRadioButton("Try click here, focus will be here."));
slides.add(p);
public void showCurrent() {
if (current < 0 || current >= slides.size())
return;
JPanel p = slides.get(current);
this.contentPanel.add(p, java.awt.BorderLayout.CENTER);
this.pack();
Component[] comps = p.getComponents();
if (comps.length > 0) {
comps[0].requestFocus(); // try delete this line
this.repaint();
public void goNext(ActionEvent e) {
if (current + 1 >= slides.size())
return;
this.contentPanel.remove(slides.get(current));
current++;
sleep(100);
this.showCurrent();
public void goBack(ActionEvent e) {
if (current <= 0)
return;
this.contentPanel.remove(slides.get(current));
current--;
sleep(100);
this.showCurrent();
public static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (Exception e) {
e.printStackTrace();
public static void main(String[] args) {
KeyLock wizard = new KeyLock();
wizard.setVisible(true);
}The first program will lead to keyboard-lock in RHEL 4 and red flag 5, both J2SE 5 and 6.
//---second -----------------------------------------
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class KeyFocusLost extends JFrame {
private JButton btnPopup = new JButton();
private JTextField jTextField1 = new JTextField();
private JPasswordField jPasswordField1 = new JPasswordField();
private JPanel jPanel1 = new JPanel();
private JScrollPane jScrollPane3 = new JScrollPane();
private JTree jTree1 = new JTree();
private JButton btnAbout = new JButton("About");
public static final String aboutMsg =
"<html> This program is used to find keyboard focus lost problem.<br>" +
"Click 'popup' button in main window, or select any node in the tree and press F6,<br>" +
"a dialog popup, and click ok button in the dialog,<br>" +
"keyboard focus will lost in main window." +
"</html>";
public KeyFocusLost() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("Keyboard focus test");
getContentPane().setLayout(null);
btnPopup.setBounds(new Rectangle(33, 482, 200, 35));
btnPopup.setMnemonic('P');
btnPopup.setText("Popup and lost focus");
btnPopup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopupDialog dlg = new PopupDialog(KeyFocusLost.this);
dlg.setVisible(true);
btnAbout.setBounds(new Rectangle(250, 482, 100, 35));
btnAbout.setMnemonic('A');
btnAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(KeyFocusLost.this, aboutMsg, "About", JOptionPane.INFORMATION_MESSAGE);
jTextField1.setText("Try input here, and try input in password box below");
jTextField1.setBounds(new Rectangle(14, 44, 319, 29));
jPasswordField1.setBounds(new Rectangle(14, 96, 319, 29));
jPanel1.setBounds(new Rectangle(14, 158, 287, 291));
jPanel1.setLayout(new BorderLayout());
jPanel1.add(new JLabel("Select any node in the tree and press F6."), java.awt.BorderLayout.NORTH);
jPanel1.add(jScrollPane3, java.awt.BorderLayout.CENTER);
jScrollPane3.getViewport().add(jTree1);
Object actionKey = "popup";
jTree1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), actionKey);
jTree1.getActionMap().put(actionKey, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
PopupDialog dlg = new PopupDialog(KeyFocusLost.this);
dlg.setVisible(true);
this.getContentPane().add(jTextField1);
this.getContentPane().add(jPasswordField1);
this.getContentPane().add(jPanel1);
this.getContentPane().add(btnPopup);
this.getContentPane().add(btnAbout);
public static void main(String[] args) {
KeyFocusLost keytest = new KeyFocusLost();
keytest.setSize(400, 600);
keytest.setVisible(true);
static class PopupDialog extends JDialog {
private JButton btnOk = new JButton();
public PopupDialog(Frame owner) {
super(owner, "popup dialog", true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.getContentPane().setLayout(null);
btnOk.setBounds(new Rectangle(100, 100, 200, 25));
btnOk.setMnemonic('O');
btnOk.setText("OK, then focus lost");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopupDialog.this.getOwner().toFront();
try {
Thread.sleep(100); // try delete this line !!!
} catch (Exception ex) {
ex.printStackTrace();
PopupDialog.this.dispose();
this.getContentPane().add(btnOk);
this.getRootPane().setDefaultButton(btnOk);
this.setSize(400, 300);
}The second program will lead to keyboard-focus-lost in RHEL 3/4 and red flag 4/5, J2SE 5, not in J2SE 6.
And I also tried java demo program "SwingSet2" in red flag 5, met keyboard-lock too.
I guess it should be some kind of incompatibleness of J2SE with some Linux platform. Isn't it?
Please help, thanks.Hi.
I have same problems on Ubuntu with Java 6 (all versions). I would like to use NetBeans or IntelliJ IDEA but it is not possible due to keyboard locks.
I posted this bug
https://bugs.launchpad.net/ubuntu/+bug/174281
before I found some info about it:
http://forums.java.net/jive/thread.jspa?messageID=189281
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6506617
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6568693
I don't know from which part this bug comes, but I wonder why it isn't fixed yet. Does anybody else use NetBeans or IntelliJ IDEA on linux with Java 6 ?
(I cannot insert link :\ ) -
Running a Swing program from another program
I'm having what is most likely newbie problems since I'm relatively new to Swing programming. Basically my situation is this: I've got a program that looks at its command line parameters and either runs through a series of actions or presents a Swing GUI to allow the user to step through the actions one by one.
My problem is that I bascially don't know how to call (instantiate, declare, etc.) the GUI from my Java code. I tried implementing the GUI class with a runnable interface, but evertime I try to invoke the start on the interface I'm getting an error. I have a feeling I'm just missing something. The Swing GUI works fine if I call it on its own so it's the code the invokes it from the small command line processor that I'm goofing up somehow.
So to recap, I have a small Java app that I'm trying to call a GUI that I've built and can't seem to get the code right.
Any pointers to examples or explanation on how to accomplish the above are welcome.
Thanks,
EdThat the "2" is printed out immediately is as expected, but I don't understand why the JVM exits. The following is, AFAIK, a trimmed down version of what you are doing, and if you run it you'll see that the frame remains until you close it manually:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ShowFrame {
public static void main(String[] args) {
AppFrame gui = new AppFrame();
gui.run();
private static class AppFrame extends JFrame implements Runnable {
public AppFrame() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton btn = new JButton("Close");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AppFrame.this.dispose();
getContentPane().add(btn);
pack();
setLocationRelativeTo(null);
public void run() {
System.out.println("1");
this.setVisible(true);
System.out.println("2");
}Maybe someone else can shed some light over your problem... -
Placing a telnet session within a java swing program
I was wondering if there was a way to maybe anchor a telnet session into a JPanel within a Java Swing program. Most of my users end up running a telnet session while using my Swing Program and I was hoping to find a way to bring the two together. If this is possible could someone point me in the right direction (like an online resource) that might show me how to do this.
You could use sockets and a TextArea and build your own simple telnet application.
Socket tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html -
Swing program - how to increase the size
Hi Friends,
I have made a simple swing program and it works fine.But I am not able to make the size(width,height) of the panel.Can someone please tell me how can i do that.Here's some part of my code...
public class Test extends JPanel
implements ActionListener {
//instance variable declared here
public Test() {
super(new BorderLayout());
//code for buttons,labels etc
JPanel buttonPanel = new JPanel(); //use FlowLayout
add(buttonPanel, BorderLayout.PAGE_START);
public void actionPerformed(ActionEvent e) {
//lots of code
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new Test();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Thanks for your help.OK sorry for that,in future i will post it in the right place.I tried doing this but didn't worked:
JPanel buttonPanel = new JPanel(); //use FlowLayout
// buttonPanel.setSize(300, 300);I was followin the FileChooserDemo example from this link:
http://java.sun.com/docs/books/tutorial/uiswing/components/examples/index.html#FileChooserDemo
And they used the pack there....now can you help please. -
Which is the best user-friendly IDE for swing program development
Which is the best user-friendly IDE for swing program development
I have seen Sun's Forte and IBM's Visual Age for Java.
But Borland's JBulider 7 Personal Edition is far more superior than any of these.Borland's JBuilder is the Best.
Ranga. -
Hi
I have a programming question here. I spent a lot of time doing it, but I still can't get it. Here is the question :
Write a method called countTo that takes one integer as a parameter and prints a
comma-separated list of the numbers from 1 to the value of the parameter, or an
appropriate error message if the parameter is less than one. In either case (if a list
of numbers is printed, or an error message is printed), after printing, the cursor
should be advanced to the next line.
For example, if the parameter has a value of 1, the method should just print the
the value 1 to the screen followed by a new-line character. If parameter has a value
of 5, the method should print the following (exactly as shown, make sure there is
no comma after the last value, and that all values are on one line with no spaces
between them):
1,2,3,4,5
This method should only print to the screen, and should not return a value.I have a programming question here. I spent a lot of
time doing it, but I still can't get it. Please post what you have done so far. -
Error on compling the Swing program
Hi all,
I am trying to run a Login Swing program. I am want to go to the next page on click of the LOGIN button.Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class login extends JFrame implements ActionListener {
public login(){
setTitle("Login Page");
//setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container pane = getContentPane();
FlowLayout layout = new FlowLayout();
pane.setLayout(layout);
JLabel loginId = new JLabel("LoginId : ", JLabel.CENTER);
JTextField Id = new JTextField(20);
if(Id.equals("shri"))
System.out.println("login successful");
JLabel password = new JLabel("Password : ", JLabel.CENTER);
TextField pwd = new TextField(20);
pwd.setEchoChar('*');
JButton Enter = new JButton("Log in");
private void actionPerformed(ActionEvent e)) {
String read = Id.getText();
String in = new String(pwd.getText());
//validate login and password here. validity will be done by sending login/password to the server
if (read.equals("Shri") && in.equals("Shri")) {
System.out.println("login successfull");
} else {
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
Id.setText("");
pwd.setText("");
Id.requestFocusInWindow();
pane.add(loginId);
pane.add(Id);
pane.add(password);
pane.add(pwd);
pane.add(Enter,BorderLayout.CENTER);
setContentPane(pane);
pack();
public static void main(String[] args) {
login enter = new login();
I'm getting the error->The type login must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
void is an invalid type for the variable actionPerformed
Syntax error on token "(", ; expected
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
Please help me resolve this error and also to improvise the code.You code had basic problem like declaration errors. Have modified your code.
Try this.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame implements ActionListener {
JLabel loginId;
JTextField Id;
TextField pwd;
public Login(){
setTitle("Login Page");
//setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container pane = getContentPane();
FlowLayout layout = new FlowLayout();
pane.setLayout(layout);
loginId = new JLabel("LoginId : ", JLabel.CENTER);
Id = new JTextField(20);
if(Id.equals("shri")) {
System.out.println("login successful");
JLabel password = new JLabel("Password : ", JLabel.CENTER);
pwd = new TextField(20);
pwd.setEchoChar('*');
JButton Enter = new JButton("Log in");
pane.add(loginId);
pane.add(Id);
pane.add(password);
pane.add(pwd);
pane.add(Enter,BorderLayout.CENTER);
setContentPane(pane);
pack();
public void actionPerformed(ActionEvent e) {
String read = Id.getText();
String in = new String(pwd.getText());
//validate login and password here. validity will be done by sending login/password to the server
if (read.equals("Shri") && in.equals("Shri")) {
System.out.println("login successfull");
} else {
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
Id.setText("");
pwd.setText("");
Id.requestFocusInWindow();
public static void main(String[] args) {
Login enter = new Login();
} -
Best Book for Swing Programming
Can anyone tell me the name of a swing related book which covers all the major topic of swing programming.
Thanks in advanceI like Java Swing from OReilly. Big thick book, and contains nothing but Swing.
-
Font problem when executing a swing program
Hi! I'm learning to write a simple swing program. The program compiled successfully. When I excuted it, everything worked fine except that I got the following error message:
Font specified in font.properties not found [--symbol-medium-r-normal--*-%d-*-*-p-*-adobe-fontspecific]
It's somewhat annoying. Do you have any solution?
Thank you,
LihengThank you. I tried to run Font2DTest. But it didn't work, "Exception in thread "main" java.util.zip.ZipException: No such file or directory"
I'll keep trying.......
In JDK under the directory demo/jfc/Font2DTest, there
is a demo program that shows all available fonts on
your system. You can find the available font names.
Then in the font.properties file in jre/lib, search
for the font name in your error message and replace it
with an available name from Font2DTest.
Are you using Unix? What OS, Solaris, Linux? -
How to start Swing programs without console
Hi, I'm working on Swing program, which can be started in the MS-DOS console by typing:
java myProgram
This works great, but for the end-users, I don't want them to see the ugly console that shows up and occasionally display exception code. How do I get the Swing program to start up without having the accompanying console?
Any help is appreciated. Thanks! :-)you can also package it in a jar and make it executable. There's a good discussion in the Jar Forum about how to do that.
-
Produce EXE files for Swing programs using Visual J++?
There's a way to make VJ++ to compile Swing programs:
http://www.stanford.edu/class/cs108/usingvj.html
But the exe file VJ++ produces won't run though... Does anyone know how to make it work? Thanx in advanceTestStand 4.0.1 was released well before Visual Studio 2012 existed so the automatic step into behavior from TestStand that launches visual studio and attaches it as a debugger likely does not work.
But you can just attach to the seqedit.exe process from Visual Studio and set breakpoints in your code and debug teststand just like you would any other process from Visual Studio. Make sure that when you attach with Visual Studio that you make sure you have it set to debug native code.
Hope this helps,
-Doug -
Can anyone please provide code for me to insert a custom timer into a
swing program? I need a clock that will run concurrently with the program. Any tips???I have a similar problem...
Class:
import java.awt.*;
import hsa.Console;
import java.sql.Time;
import javax.swing.JTextField;
public class CustomTimer extends Thread implements Runnable
int secs = 0, mins = 0, hours = 0, day = 1, month = 1, year = 2006;
Time timer;
Thread main;
public CustomTimer ()
super ();
public void start ()
main = new Thread ();
main.start ();
public void run (JTextField pasteInHere)
while (year != 2008)
timer = new Time (hours, mins, secs);
secs++;
if (secs == 60)
secs = 0;
mins++;
if (mins == 60)
mins = 0;
hours++;
if (hours == 24)
hours = 0;
day++;
if (day == 28 & month == 2)
day = 0;
month++;
else if (day == 30 & (month == 2 | month == 4 | month == 6 | month == 9 | month == 11))
day = 0;
month++;
else if (day == 31)
day = 0;
month++;
if (month == 12)
month = 0;
year++;
try
main.sleep (100);
pasteInHere.setText ("" + day + "/" + month + "/" + year + " " + timer);
catch (InterruptedException ie)
Program:
import javax.swing.*;
import java.awt.*;
public class ClockTest extends JFrame
public ClockTest ()
Container contents = getContentPane ();
setSize (500, 500);
JPanel hi = new JPanel ();
JTextField hello = new JTextField ();
CustomTimer ct = new CustomTimer ();
ct.run (hello);
hi.add (hello);
contents.add (hi);
public static void main (String[] args)
new ClockTest ().show ();
Can anyone tell me why the clock does not run concurrently with the program? -
Beginning Swing programming problem
My classmates and I are trying to write a simple Swing program with a single button and a text field that contains the number of times the button has been pressed since the program started. The problem is that in the ActionPerformed method, any changes to the text field ends up with multiple event errors. It will print the count fine to the command prompt, but not the GUI. Any insight would be greatly appreciated.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class CounterGUI extends JFrame implements ActionListener
public int count = 0;
Container contents = getContentPane();
JTextField counter;
final String temp = "Total times pressed: ";
public CounterGUI()
final int width = 300;
final int height = 300;
setSize(width, height);
JTextField counter = new JTextField(temp + count);
counter.setEditable(false);
JButton clicker = new JButton("Click me!");
clicker.addActionListener(this);
clicker.setActionCommand("Click");
contents.add(counter, "Center");
contents.add(clicker, "South");
public void actionPerformed(ActionEvent e)
String command = e.getActionCommand();
if(command == "Click")
count++;
counter.setText(temp + count);
System.out.println(count);
public static void main(String[] args)
JFrame f = new CounterGUI();
f.addWindowListener(new WindowCloser());
f.setVisible(true);Hi Guys,
The line JTextField counter = new JTextField(temp + count); is declared in the constructor, this means that the field counter is not visible to other methods and you'll get a null pointer exception (NPE) when you try to access the class field counter
Change to counter = new JTextField(temp + count); Now if you were catching and displaying exceptions you'd notice that this was happening.
Dave
Maybe you are looking for
-
Vi with access via both user interface and external communicat​ion
Hi, Maybe a little bit too general but I'll risk it: It concerns a project to stear a tensile machine. Data acquisition is relative straightforward via a few analogue and digital channels. The interaction of the operator with the tensile machine can
-
Prompted to update to latest version of iTunes but it comes up with a Microsoft C visual error
Prompted to update iTunes on my Laptop but it fails and comes up with a Microsoft C++ runtime error R6034 then another error window with iTunes error 7 (Windows error 1114
-
How in the hell do you remove the edit button from the bookmarks and netlet channels?
I have removed the check box for the edit functionality of both these channels and restarted the portal server. Yet, the edit button is still there on both channels and it allows the user to edit (duh) the targets of the netlet and bookmarks. WHAT EL
-
Hi Experts , Error In OM
Hi Experts, We are in post go live support stage. Error ; When we are delimiting the position in OM. It is asking Request Number. How to overcome this. Please provide me the answer. Thanks & Regards, Vinay
-
dear all i have finished the middleware configuration and in the mobile administrator i have deployed the mobile component (MDSD 2.1) and now i want to install it on the mobile client (windows mobile 6.0) how can i deploy the DB2E .. i have a file D