Applet - Text field issue
Hello all,
I have an issue in my applet containing text filed. In my applet, the SetText function of the textfiled will be executed continuously to update a particular status. The text filed used is read only.
When i double click the text filed during the SetText function is being executed , the applet hangs.
The text filed will be updated continuously using thread.
May i know the reason why it gets hanged. Help me in this issue.
Waiting for a positive reply.
Applet - Text field issue
Hello all,
I have an issue in my applet containing text filed. In my applet, the SetText function of the textfiled will be executed continuously to update a particular status. The text filed used is read only.
When i double click the text filed during the SetText function is being executed , the applet hangs.
The text filed will be updated continuously using thread.
May i know the reason why it gets hanged. Help me in this issue.
Waiting for a positive reply.
Re: Applet - Text field issue
Can you make a small complete program that compiles, executes and shows the problem that we could use for testing to see what the code is doing?
Re: Applet - Text field issue
here is my sample code. but in this code, the applet was running successfully.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication18;
import javax.swing.UIManager;
public class Test1 extends javax.swing.JApplet {
/**
* Initializes the applet Test1
*/
@Override
public void init() {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Test1.class.get Name()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Test1.class.get Name()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Test1.class.get Name()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Test1.class.get Name()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
try
{
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel ");
}
catch (Exception ex)
{
System.out.println (ex);
//ex.printStackTrace();
}
initComponents();
TestThread objTestThread = new TestThread (jTextField1);
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* This method is called from within the init() method to initialize the
* form. WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField1.setEditable(false);
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(101, 101, 101)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(171, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(243, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication18;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
public class TestThread implements Runnable{
JTextField jtf;
Thread objThread;
int iVal = 0;
TestThread (JTextField tx1){
jtf = tx1;
objThread = new Thread (this);
objThread.start();
}
@Override
public void run() {
while (true){
WaitThread (100);
if (iVal ++ == 20)
iVal = 0;
jtf.setText (""+iVal);
}
}
public synchronized void WaitThread (long lTimeOutVal)
{
try
{
wait (lTimeOutVal);
}
catch (InterruptedException ExceWait)
{ }
}//End WaitTableThread
}
Re: Applet - Text field issue
Quote:
applet was running successfully.
The code needs to show the problem.
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
Re: Applet - Textfiled Issue
Moved from Java Software.
If you can't judge from the title of a forum whether it's the right place to post, just go through a few threads. If you had done that you would have clearly seen that your question doesn't belong there.
Go through this tutorial: Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing) . and if you're not using Swing, tell us what you are using, along with a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
Oh, and Java doesn't have functions. Java has methods.
db
Re: Applet - Text field issue
Re: Applet - Text field issue