can anybody tell me whats wrong?
i keep getting the numberformatexception when i try to run this program.
here is my action listener.
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
String s = t2.getText();
int r = Integer.parseInt("s");
if (t1.getText().equals("1") && (r <= 19)){
JOptionPane.showMessageDialog(null, "sdskd");
}
The image is accessible as an URL from either the class-path or the document base. An applet will typically not be able to load an image from the client PC, which is what that applet is trying to do.
Other tips:
For better help sooner, post an SSCCE.
Ensure the Java Console is configured to show for applets & JWS apps. If there is no output at the default level, raise it and try again.
Few notes about your code
Your code is not extending the JApplet
You are not implementing the public void sart() method.
You are not implementing the public void init() method.
And most importantly you are missing this
Related
I am moving from SSIS to Pentaho, also new in java. What I would like to do is to show a simple message box in Pentaho using the Defined Java Class step (or another one).
First I tried with this code:
import javax.swing.JOptionPane;
public class MyClass
{
public static void main(String args[]){
JOptionPane.showMessageDialog(null,"Hello, this message is in a message type box." );
System.exit(0);
}
}
But I got this error:
Non-abstract class "Processor" must implement method "boolean org.pentaho.di.trans.steps.userdefinedjavaclass.TransformClassBase.processRow
I modified the code:
import javax.swing.JOptionPane;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
JOptionPane.showMessageDialog(null,"Hello world!");
System.exit(0);
return true;
}
I tested the class, I did not receive any error message, but I could not see the message box that I was expecting.
So, my question is, what else do I need to import, specify or modify in order to achieve what I want to do.
Regards.
In pdi transformations most steps require some input. Your processRow() method is called for each row, received by your User Defined Java Class step. So, if you don't have input row - the method is not called.
You may want to place some step, producing one row before and pass the output to the java step. You may use "Detect empty stream" step - it will output exactly one row without any columns. However, your java code would still require some adjustments (not sure what exactly you need to do it in java, but it seems, like you need to create some ).
So, the easiest option for you would be to use "Modified Java Script Value" (it uses Rhino javascript, not java) step and call Alert("Hello world!") function inside. But nevertheless you would still need an input row.
If you still want to do it java way, you may try following code (but I am not a java developer, so I am not sure how good that code is):
import javax.swing.*;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
if (first)
{
first = false;
myFrame = new MyFrame();
// myFrame.setVisible(true);
JOptionPane.showMessageDialog(myFrame, "Hello world");
myFrame.dispose();
}
return true;
}
private MyFrame myFrame;
private class MyFrame extends JFrame {
public MyFrame() {
super();
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Also, please keep in mind, that kettle jobs/transformations usually are not supposed to be interactive. They may be executed on linux systems, which may have no windowing system.
So displaying such messages is usually used only for debugging and is disabled in production versions.
I would really appreciate your help;
I'm using java (netbeans ide), i'm working with filechooser, when i choose a directory, i need to display it's path on a jtextfield. However nothing appears until the program is over (untill all the files of the directory are parsed and treated), I would like it to appear as soon as the program starts.
Please help me out, here is my code:
JFileChooser fch = new JFileChooser("C:\\");
fch.addChoosableFileFilter(filter);
fch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = fch.showOpenDialog(null);
int apr=0;
if (ret==JFileChooser.APPROVE_OPTION)
{
apr=1;
jTextField1.setText(fch.getSelectedFile().toString());
}
else jTextField1.setText("Nothing clicked!!!");
.......... the rest of the code .........
when I don't click the msg appears, yet when i do, the path won't apprear till after the program is finished
The code of JFileChooser... probably resides in an ActionListener. This is handled on the sole event handling thread. So do an invokeLater.
#Override
public void actionPerformed(ActionEvent event) {
...
EventQueue.invokeLater(new Runnable() { // Added
... rest of the code
}); // Added
}
Here I think "rest of the code" might be causing the delay, but you might try differently.
This is for a kiosk application where this message is not desired. It's odd because Mac doesn't display this message in either browser -- seems to only happen on Ubuntu.
Using this example applet on Ubuntu 10, Firefox 12, I was able to reproduce the message "Applet initialized," illustrated below. It doesn't appear to be from an overridden init(), and the super implementation is empty; I presume it's a feature of either the plug-in or the browser itself. Oddly, the message actually moves from one lower corner of the browser window to the other, as the mouse cursor approaches it.
For embedded use, consider starting the applet (or hybrid application) via java-web-start as shown in the example.
Addendum: Andrew's example produces the message "Applet started."
Seems like futzing to me, but if by 'status bar' you mean the little bar at the bottom of older browsers, try using Applet.showStatus("") at the end of init() or start().
Edit: Using the following command produces the expected result in appletviwer.
$ appletviewer NoMessageApplet.java
Code:
// intended only to show attributes - view in browser
// <applet code='NoMessageApplet' width=400 height=400></applet>
import java.awt.BorderLayout;
import javax.swing.*;
public class NoMessageApplet extends JApplet {
String noMessage = " Nobody Here But Us Chickens..";
JTextArea output;
#Override
public void init() {
try {
SwingUtilities.invokeAndWait( new Runnable() {
public void run() {
initGui();
}
});
} catch(Exception e) {
e.printStackTrace();
}
}
public void initGui() {
JPanel gui = new JPanel(new BorderLayout(5,5));
output = new JTextArea(5,20);
gui.add(new JScrollPane(output));
setContentPane(gui);
setMessage("initGui()" + noMessage);
}
#Override
public void start() {
setMessage("start()" + noMessage);
}
/** Both sets the message as the 'status' message &
appends it to the output control */
public void setMessage(final String message) {
SwingUtilities.invokeLater( new Runnable() {
public void run() {
output.append(message + "\n");
}
});
showStatus(message);
}
}
This is not a direct answer to your question but definitely a possible solution to your problem (Was a comment. Added as an answer as suggested by #Andrew Thompson):
If it is a kiosk application then why is there a status bar at all?
If you have control over the system where the application is used from (or where the browser is installed), you can either deactivate the status bar in the browser or make the browser to be displayed always in full screen mode.
Most kiosk applications operate this way.
FF13 fixed it (so does the most recent version of Chrome). Both now currently do not enable status bar's by default (they did when I made this initial post). Not quite an answer, but an answer that worked for me.
I am trying to check that the text in a JTextField matches a perticular pattern, and if it does / doesn't display a message the user. This is what I have so far:
public class input extends KeyListener{
// Some code here
final JTextField inputField = new JTextField(35);
// Some more code...
public void generate(){
// Some GUI code here...
inputField.addKeyListener(this);
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
if(e.getSource() instanceof JTextField && e.getSource().equals(inputField)){
if(Pattern.matches("../../....", (JTextComponent) e.getSource()).getText())))
System.out.println("Yh, it works");
else System.out.println("EPIC FAIL (LOL)");
}
}
}
And it does actually work almost perfectly. However, if I paste something using CTRL + V, I have to type two more characters (as opposed to one) before the KeyListener registers that the string is different! So does any one have any idea's why?
Sorry if I have missed out any details - I have tried to make the post as short and concise as possible; so please don't hesitate to ask anything...
For starters, don't use a KeyListener for this type of problem as it is doomed to fail, and even if you get it to work, it's a kludge at best. Instead I'd use either an ActionListener if I wanted to do my checking after the user is completely done entering information, or a DocumentListener if I want to check input as a user is entering, but am not going to block that entering or change the displayed text, or a Document Filter if I'm going to check the input as the user is entering and block it or change it if it is not appropriate.
hi i have a full screen program which i dont want people to close unless they have a password i have this code at the moment
public void windowClosing(WindowEvent arg0)
{
System.out.println("HERE");
String inputValue = JOptionPane.showInputDialog("Please input the closeword");
if (inputValue != "closeplz")
{
}
}
in the if statement i want it to stop the method so that the program doesent close. any help would be greatly aprecheated thanks ste
You have to call
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
on (or within) the JFrame instance. Then the frame will not close unless you do it manually, though windowClosing() will still be called. Inside it, you can then conditionally call
System.exit(1);
which will end the application. Be sure to do any necessary cleanup first.
Check out Closing an Applicaton for a simple class to help you with this. You would need to provide the custom close action that prompts the user for the password.
Using your simple example the code would be:
Action ca = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
JFrame frame = (JFrame)e.getSource();
String inputValue = JOptionPane.showInputDialog("Please input the closeword");
if (! inputValue.equals("closeplz"))
{
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
};
CloseListener cl = new CloseListener(ca);