|
|
#1 |
|
In Runtime
|
Okay, I've programmed a Java application in Eclipse. It was working fine but now the JFrame won't show. After investigating, I found two errors that Eclipse wasn't giving me by compiling it manually.
Code:
AutoTyper.java:16: cannot find symbol
symbol : class SmartRobot
location: class org.smartrobot.AutoTyper
SmartRobot robot = new SmartRobot();
^
AutoTyper.java:16: cannot find symbol
symbol : class SmartRobot
location: class org.smartrobot.AutoTyper
SmartRobot robot = new SmartRobot();
^
|
|
|
|
|
|
#2 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Is SmartRobot definitely being compiled ok without any errors?
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
#3 |
|
In Runtime
|
Yes. What I gather is that for some reason, just on that line, it cannot find 's'?
|
|
|
|
|
|
#4 | |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Quote:
I'd really need to see the project to help further - if the SmartRobot class has no errors, is being compiled ok and is located in the same package and folder as the referring class (or the appropriate import statement is used) I don't see any reason why it'll come up with that error.
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
|
#5 | |
|
Daemon Poster
Join Date: Dec 2008
Posts: 1,465
|
Quote:
__________________
Raidmax Smilodon Extreme Black Case -|-AMD Phenom II x4 955 BE @ 3829.50 Mhz (18.5 x 207, vcore 1.424, NB 2600 mhz, HT link 2200 mhz) -|- Xigmatek Dark Knight S1283V -|- Gigabyte MA790XT-UD4P Mobo -|- G. Skill 6Gb (3 x 2Gb) DDR3 1333 RAM 7-7-7-18-2t -|- WD Caviar 7200 RPM 1 TB HDD -|- OCZ GameXtreme 700W -|- Radeon 4870 1Gb @ 780/1050 -|- Asus VW202NR 20" wide-screen -|- Windows 7 Professional 64 Bit -|- Saitek Cyborg Keyboard -|- Razer Lachesis Mouse |
|
|
|
|
|
|
#6 | ||
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Quote:
Quote:
__________________
Save the whales, feed the hungry, free the mallocs. |
||
|
|
|
|
|
#7 |
|
In Runtime
|
Okay, I removed that line and it did compile perfect and fine, but the frame still isn't showing! Yes, I set visible to true.
AutoTyper Code:
package org.smartrobot;
import java.awt.AWTException;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class AutoTyper {
protected static boolean On = false;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(250, 100);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField field = new JTextField();
JButton start = new JButton("Start");
JButton stop = new JButton ("Stop");
field.setColumns(20);
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
On = true;
}
});
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
On = false;
}
});
for(int s = 0; s < 1;) {
if(On) {
for (int i = 0; i < 35000;) {
i++;
if(i == 35000) {
i = 0;
}
}
}
}
frame.add(field);
frame.add(start);
frame.add(stop);
frame.setVisible(true);
}
}
SmartRobot Code:
package org.smartrobot;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class SmartRobot extends Robot {
public SmartRobot() throws AWTException {
super();
}
public void keyType(int keyCode) {
keyPress(keyCode);
delay(50);
keyRelease(keyCode);
}
public void keyType(int keyCode, int keyCodeModifier) {
keyPress(keyCodeModifier);
keyPress(keyCode);
delay(50);
keyRelease(keyCode);
keyRelease(keyCodeModifier);
}
public void type(String text) {
String textUpper = text.toUpperCase();
for (int i=0; i<text.length(); ++i) {
typeChar(textUpper.charAt(i));
}
}
private void typeChar(char c) {
boolean shift = true;
int keyCode;
switch (c) {
case '~':
keyCode = (int)'`';
break;
case '!':
keyCode = (int)'1';
break;
case '@':
keyCode = (int)'2';
break;
case '#':
keyCode = (int)'3';
break;
case '$':
keyCode = (int)'4';
break;
case '%':
keyCode = (int)'5';
break;
case '^':
keyCode = (int)'6';
break;
case '&':
keyCode = (int)'7';
break;
case '*':
keyCode = (int)'8';
break;
case '(':
keyCode = (int)'9';
break;
case ')':
keyCode = (int)'0';
break;
case ':':
keyCode = (int)';';
break;
case '_':
keyCode = (int)'-';
break;
case '+':
keyCode = (int)'=';
break;
case '|':
keyCode = (int)'\\';
break;
// case '"':
// keyCode = (int)'\'';
// break;
case '?':
keyCode = (int)'/';
break;
case '{':
keyCode = (int)'[';
break;
case '}':
keyCode = (int)']';
break;
case '<':
keyCode = (int)',';
break;
case '>':
keyCode = (int)'.';
break;
default:
keyCode = (int)c;
shift = false;
}
if (shift)
keyType(keyCode, KeyEvent.VK_SHIFT);
else
keyType(keyCode);
}
@SuppressWarnings("unused")
private int charToKeyCode(char c) {
switch (c) {
case ':':
return ';';
}
return (int)c;
}
}
|
|
|
|
|
|
#8 | |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Quote:
The problem is here: Code:
for(int s = 0; s < 1;) {
if(On) {
for (int i = 0; i < 35000;) {
i++;
if(i == 35000) {
i = 0;
}
}
}
}
frame.add(field);
frame.add(start);
frame.add(stop);
frame.setVisible(true);
Since you never break out of that loop, all the statements below it (including the setVisible() method call) never get executed, thus the frame is never shown.
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
|
#9 |
|
In Runtime
|
Okay, so that works, but I just can't figure out how to make it constantly check for On without a loop!
|
|
|
|
|
|
#10 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Code:
for(int s = 0; s < 1;) {
if(On) {
for (int i = 0; i < 35000;) {
i++;
if(i == 35000) {
i = 0;
}
}
}
}
It's just doing some pointless counting at present. Generally speaking, infinite loops are a bit of a code smell - if you've got one something's probably not right!
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|