Jump to content

Elnof

Members
  • Content Count

    39
  • Joined

  • Last visited

Everything posted by Elnof

  1. I've tried both of those, and I got the same result. I'll try again tomorrow, but I don't think that it will help.
  2. My Javascript code is unable to access any of my java code. Where's my problem?java script: function getFile(pURL) { var text; document.getElementById('mainText').innerHTML = "<p>Loading Text...</p>"; text = document.textReadApp.javascriptCommandReadFile(pURL); if(text != "-1") { repairText(text); } else { document.applets("textReadApp").innerHTML = "<p>Error in load</p>"; }}function repairText(string) { var text; var text2; var homeLink = "<a onClick=\"getFile('addon/text/home.ntk')\" class=\"homeLink\">Home</a>"; text = String.replace(/~h~/gi, homeLink); text2 = text.replace(/~p~/gi, "<p>") text = text2.replace(/~!p~/gi, "</p>"); text2 = text.replace(/~img~/gi, "<img src=\""); text = text2.replace(/~!img~/gi, "\" />"); text2 = text.replace(/~sup~/gi, "<a href=\"#footNotes\"><div class=\"sup\">"); text = text2.replace(/~!sup~/gi, "</div></a>"); text2 = text.replace(/~n~/gi, "<br />"); text = text2.replace(/~l~/gi, "<hr class=\"textLine\" />"); placeText(text);}function placeText(finText) { document.getElementById('mainText').innerHTML=finText;} And my java: import java.awt.*;import java.io.*;import javax.swing.*;public class webTextReader extends JApplet { /** * */ private static final long serialVersionUID = 1L; /** * @param args */ public String javascriptCommandReadFile(String path) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(path); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String result = null; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console result += strLine; } //Close the input stream in.close(); return result; } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } return "-1"; } public static void main(String args[]) { }} Everytime I try to run it, I get: Error: Object doesn't support this property or method. Why is it doing this? I've tried it on IE7 and FireFox 2.0.2.
  3. Ok, I've got my ajax, is there anyway to do it using local drives? This is going to be stored on my computer, and I'm getting a javascript error telling me that my script doesn't have permission to acess the file I want to read. Here's my scipt function getFile(pURL) { pFunc = 'repairText'; document.getElementById('mainText').innerHTML = "<p>Loading Text...</p>"; if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc xmlhttp=new XMLHttpRequest(); eval('xmlhttp.onreadystatechange='+pFunc+';'); xmlhttp.open("GET", pURL, true); // leave true for Gecko xmlhttp.send(null); } else if (window.ActiveXObject) { //IE xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); if (xmlhttp) { eval('xmlhttp.onreadystatechange='+pFunc+';'); xmlhttp.open('GET', pURL, false); xmlhttp.send(); } }}function repairText() { var text; var ready = 0; var text2; if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { text=xmlhttp.responseText; ready = 1; } } if(ready == 1) { text2 = text.replace(/~p~/gi, "<p>") text = text2.replace(/~!p~/gi, "</p>"); text2 = text.replace(/~img~/gi, "<img src=\""); text = text2.replace(/~!img~/gi, "\" />"); text2 = text.replace(/~sup~/gi, "<div class=\"sup\">"); text = text2.replace(/~!sup~/gi, "</div>"); text2 = text.replace(/~n~/gi, "<br />"); text = text2.replace(/~l~/gi, "<hr class=\"textLine\" />"); placeText(text); }}function placeText(finText) { document.getElementById('mainText').innerHTML=finText;}
  4. I've been doing javascript for a while, but I've never had to do this before. So, here's my question: Is it possible to get the text from a file and put it on the web page using javascript?Thanks in advance!
  5. Elnof

    Help

    Well, I've got it working now!PS: is their a way to make my own properties? So I could do something like: cheese.startCutting(1.00); Or something?
  6. Elnof

    Unknown error

    I tried, it didn't work...
  7. Elnof

    Unknown error

    My server doesn't show the code, it acts like its a blank HTML document (it is set up for PHP). It runs a simple "hello world" program, but not this. Is there any typo's? <?php function displayPage($String) { return str_replace("_", " ", $String); } if (isset(oops)) { $comeFrom = true; $page = displayPage($_GET["oops"]); $message = "Sorry, you can not view the " . $page . " page if you are not logged in!"; } else { $message = null; } if (isset(loggedIn)) $rowSpan = 2; else $rowSpan = 1;?><html> <head> <title><?php if (comeFrom == true) echo "You're not logged in"; else echo "Log In page"; ?></title> <link rel="stylesheet" type="text/css" href="settings.css"> <script language="JavaScript1.2"> //Advanced Email Check credit- //By JavaScript Kit ([url="http://www.javascriptkit.com"]http://www.javascriptkit.com[/url]) //Over 200+ free scripts here! var testresults function checkemail(){ var str=document.getElementById('email').value; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (filter.test(str)) testresults=true else{ alert("Please input a valid email address!") testresults=false } return (testresults) } </script> <script> function checkbae(){ if (document.layers||document.getElementById||document.all) return checkemail() else return true } </script> </head> <body align="center"> <center> <div class="mainContainer"> <div class="header"> <table border="0" width="772px"> <tr> <?php echo "<td rowspan='" . $rowSpan . "'>"; ?> <div class="logo"> <img src="logo.png" alt="Nateck Logo" /> </div> </td> </tr> <tr> <td align="right"> <div class="welcome"> <?php if (isset($_SESSION["loggedIn"])) { echo "Welcome " . $_SESSION["useName"] . "!</td></tr>"; echo "<tr><td><a href='logOut.php'>Log Out</a>"; } else echo "<a href='logIn.php'>Log In</a>"; ?> </div> </td> </tr> </table> </div> <div class="navBar"> <div class="navLinks"> <ul> <li><a href="home.php">Home</a></li> <li><a href="view.php?page=news">News</a></li> <li><a href="view.php?page=products">Products</a></li> <li><a href="view.php?page=projects">Projects</a></li> <li><a href="view.php?page=forums">Forums</a></li> <li><a href="view.php?page=contact_us">Contact Us</a></li> <li><a href="view.php?page=other">Other</a></li> </ul> </div> </div> <div class="content-pane"> <div class="form-paragraph" align="left"> <a id="logInForm"></a> <h2>Log In</h2> <div class="form"> <?php if ($message != null) echo "<div class='error'>" . $message . "</div>"; ?> <form action="welcome.php" method="post"> <label for="useName">Username:</label> <input type="text" id="useName" /><br /> <label for="passWord">Password:</label> <input type="password" id="passWord" /><br /> <input type="submit" value="Log In" /> </form> <p>Don't have an account? Click <a href="signUp.php">here</a> to sign up!</p> </div> </div> <center> <hr width="768px"> </center> <table boarder="0" width="100%"> <tr> <td> <div class="form-username"> <div class="form"> <form action="forgot-email.php" method="post" onSubmit="return checkbae()"> Forgot your account information?<br /> <label for="email">Enter your e-mail:</label> <input type="text" id="email" id="email" /><br /> <input type="submit" value="Get Account Info" id="button" /> </form> </div> </div> </td> <td> <div class="form-question"> <div class="form"> <form action="secretQuestion.php" method="get"> Didn't enter your e-mail when you signed up?<br /> <label for="sQUsername">Enter your username:</label> <input type="text" id="sQUsername" /><br /> <input type="Submit" value="Secret Question" /> </form> </div> </div> </td> </tr> </table> </div> <div class="footer"> <p> This site is Copyright © 2007 Nateck - All rights reserved </p> </div> </div> </center> </body> </html>
  8. Elnof

    PHP events

    Ok, I'll do that.
  9. Elnof

    PHP events

    Is there such a thing as events in PHP? I want to use the FILTER_VALIDATE_EMAIL when the user clicks 'submit', but the only way I can think to do that is: ...<input type="submit" onClick="<?PHP if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) { echo "Enter a valid E-mail"; } else { echo "Thank You!"; } }?>" />... Would that work?
  10. Elnof

    Help

    No, cleaning the project didn't do anything that I noticed.
  11. Elnof

    Help

    Good point, now the ImageIcon that I was using is gone too.
  12. Elnof

    Help

    Ok, thanks, I think I figured it out, but now I have another problem: java.lang.NoClassDefFoundError: NXT2 Exception in thread "main" I resently changed the project name from NXT2 to Nxt_Command_Center_1_0_0. PS: The book was for the leJOS NXJ api. Not all of java. [left][left]package nxt_command_center; import java.awt.event.*; import java.awt.*; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.JTabbedPane; import javax.swing.border.Border; public class NXT_Command_Center implements KeyListener{ /** * */ private static final long serialVersionUID = (long) 1.0; Color unEdit = new Color(211, 211, 211); Frame command; final int FORWARD = 38, // Up = forward BACKWARD = 40, // Down = backward LEFT = 37, // Left = left turn RIGHT = 39, // Right = right QUIT = 27, //Escape SPACE = 32, // Space SHIFT = 16, // Shift = what ever SETTINGS = 112, //F1 = Settings ABOUT = 114, // F3 = about REPAINT = 113; //F2 = repaint Frame setIn; JFrame JAbout; boolean windowOpen = false; boolean cmOrIn = true; boolean dgOrRt = true; boolean resetYOR = false; int up1Int = 2; int up2Int = 4; int down1Int = 3; int down2Int = 5; int left1Int = 3; int left2Int = 4; int right1Int = 2; int right2Int = 5; int space1Int = 0; int space2Int = 6; int shift1Int = 1; int shift2Int = 6; int curWindow = 0; TextField output; TextField sen1; TextField sen2; TextField sen3; TextField sen4; TextField mot1; TextField mot2; TextField mot3; Panel sensors; Panel motors; Panel sensors1; Panel sensors2; Panel sensors3; Panel sensors4; Panel motors1; Panel motors2; Panel motors3; FlowLayout panelsCenter = new FlowLayout(FlowLayout.CENTER); FlowLayout panelsLeft = new FlowLayout(FlowLayout.LEFT); Label s1; Label s2; Label s3; Label s4; public class settings implements ActionListener { /** * */ private static final long serialVersionUID = 1L; Label motorALabel; Label motorBLabel; Label motorCLabel; Label upArrow; Label downArrow; Label leftArrow; Label rightArrow; Label space; Label shift; Label sonarLabel; Label motorLabel; Border loweredbevel = BorderFactory.createLoweredBevelBorder(); JTabbedPane navigation; Panel motorSettingsPanel; Panel upArrowPanel; Panel downArrowPanel; Panel leftArrowPanel; Panel rightArrowPanel; Panel spacePanel; Panel shiftPanel; Panel keySettingsPanel; Panel infoSettingsPanel; Panel motorSettingsA; Panel motorSettingsB; Panel motorSettingsC; Panel curSettings; Panel sonarPanel; Panel motorsPanel; Panel motor2; Panel checkBox; TextField motorAText; TextField motorBText; TextField motorCText; JComboBox up1; JComboBox up2; JComboBox down1; JComboBox down2; JComboBox left1; JComboBox left2; JComboBox right1; JComboBox right2; JComboBox space1; JComboBox space2; JComboBox shift1; JComboBox shift2; JRadioButton sonarCM; JRadioButton sonarIN; JRadioButton motorRT; JRadioButton motorDG; ButtonGroup sonar; ButtonGroup motor; JCheckBox reset; JButton keySubmit; JButton submitMotors; Color grey = new Color(220, 220, 220); public Panel infoSettings() { infoSettingsPanel = new Panel(new GridLayout(3,1)); sonar = new ButtonGroup(); sonarPanel = new Panel(panelsLeft); sonarLabel = new Label("Sonar:"); sonarPanel.add(sonarLabel); sonarCM = new JRadioButton("Centimeters"); sonarCM.addActionListener(this); sonarIN = new JRadioButton("Inches"); sonarIN.addActionListener(this); if (cmOrIn == true) sonarCM.setSelected(true); else sonarIN.setSelected(true); sonarCM.setBackground(grey); sonarIN.setBackground(grey); sonar.add(sonarCM); sonar.add(sonarIN); sonarPanel.add(sonarCM); sonarPanel.add(sonarIN); motor = new ButtonGroup(); motorsPanel = new Panel(new GridLayout(2,1)); checkBox = new Panel(new FlowLayout(FlowLayout.RIGHT)); motors2 = new Panel(panelsLeft); motorLabel = new Label("Motors:"); motors2.add(motorLabel); motorRT = new JRadioButton("Rotations"); motorDG = new JRadioButton("Degrees"); motorRT.setBackground(grey); motorRT.addActionListener(this); motorDG.setBackground(grey); motorDG.addActionListener(this); if (dgOrRt == true) motorDG.setSelected(true); else motorRT.setSelected(true); motor.add(motorRT); motor.add(motorDG); motors2.add(motorRT); motors2.add(motorDG); motorsPanel.add(motors2); reset = new JCheckBox("Reset when motor stops"); reset.setBackground(grey); reset.addActionListener(this); if (resetYOR == true) reset.setSelected(true); checkBox.add(reset); motorsPanel.add(checkBox); infoSettingsPanel.add(sonarPanel); infoSettingsPanel.add(motorsPanel); return infoSettingsPanel; } public Panel keySettings() { keySettingsPanel = new Panel(new GridLayout(7, 1)); upArrowPanel = new Panel(panelsLeft); downArrowPanel = new Panel(panelsLeft); leftArrowPanel = new Panel(panelsLeft); rightArrowPanel = new Panel(panelsLeft); spacePanel = new Panel(panelsLeft); shiftPanel = new Panel(panelsLeft); String[]List = {"A Forward", "A Backward", "B Forward", "B Backward", "C Forwards", "C Backwards", "None"}; //Combo Boxes for the up arrow up1 = new JComboBox(List); up2 = new JComboBox(List); up1.setSelectedIndex(up1Int); up2.setSelectedIndex(up2Int); upArrow = new Label("Up Arrow:"); upArrowPanel.add(upArrow); upArrowPanel.add(up1); upArrowPanel.add(up2); //Combo Boxes for the down arrow down1 = new JComboBox(List); down2 = new JComboBox(List); down1.setSelectedIndex(down1Int); down2.setSelectedIndex(down2Int); downArrow = new Label("Down Arrow:"); downArrowPanel.add(downArrow); downArrowPanel.add(down1); downArrowPanel.add(down2); //Combo Boxes for the left arrow left1 = new JComboBox(List); left2 = new JComboBox(List); left1.setSelectedIndex(left1Int); left2.setSelectedIndex(left2Int); leftArrow = new Label("Left Arrow:"); leftArrowPanel.add(leftArrow); leftArrowPanel.add(left1); leftArrowPanel.add(left2); //Combo Boxes for the right arrow right1 = new JComboBox(List); right2 = new JComboBox(List); right1.setSelectedIndex(right1Int); right2.setSelectedIndex(right2Int); rightArrow = new Label("Right Arrow:"); rightArrowPanel.add(rightArrow); rightArrowPanel.add(right1); rightArrowPanel.add(right2); //Combo Boxes for space space1 = new JComboBox(List); space2 = new JComboBox(List); space1.setSelectedIndex(space1Int); space2.setSelectedIndex(space2Int); space = new Label("Space Bar:"); spacePanel.add(space); spacePanel.add(space1); spacePanel.add(space2); //Combo Boxes for shift shift1 = new JComboBox(List); shift2 = new JComboBox(List); shift1.setSelectedIndex(shift1Int); shift2.setSelectedIndex(shift2Int); shift = new Label("Shift Key:"); shiftPanel.add(shift); shiftPanel.add(shift1); shiftPanel.add(shift2); keySubmit = new JButton("Submit"); keySubmit.addActionListener(this); keySettingsPanel.add(upArrowPanel); keySettingsPanel.add(downArrowPanel); keySettingsPanel.add(leftArrowPanel); keySettingsPanel.add(rightArrowPanel); keySettingsPanel.add(spacePanel); keySettingsPanel.add(shiftPanel); keySettingsPanel.add(keySubmit); return keySettingsPanel; } public Panel motorSettings() { motorSettingsPanel = new Panel(new GridLayout(4,1)); motorAText = new TextField(20); motorALabel = new Label("Motor A Power:"); motorSettingsA = new Panel(panelsCenter); motorSettingsA.add(motorALabel); motorSettingsA.add(motorAText); motorSettingsPanel.add(motorSettingsA, "North"); motorBText = new TextField(20); motorBLabel = new Label("Motor B Power:"); motorSettingsB = new Panel(panelsCenter); motorSettingsB.add(motorBLabel); motorSettingsB.add(motorBText); motorSettingsPanel.add(motorSettingsB, "Center"); motorCText = new TextField(20); motorCLabel = new Label("Motor C Power:"); motorSettingsC = new Panel(panelsCenter); motorSettingsC.add(motorCLabel); motorSettingsC.add(motorCText); motorSettingsPanel.add(motorSettingsC, "South"); submitMotors = new JButton("Submit"); submitMotors.addActionListener(this); motorSettingsPanel.add(submitMotors, "South"); return motorSettingsPanel; } //Create Settings window settings() { GridLayout setOut = new GridLayout(2,1); setOut.setHgap(0); windowOpen = true; curWindow = 2; output.setText("process: settings frame OPENED"); setIn = new Frame("Settings"); setIn.setBackground(Color.WHITE); motorSettings(); keySettings(); infoSettings(); int location = JTabbedPane.TOP; // or BOTTOM, LEFT, RIGHT navigation = new JTabbedPane(location); navigation.setBackground(grey); navigation.addTab("Motors", motorSettingsPanel); navigation.addTab("Keys", keySettingsPanel); navigation.addTab("Information", infoSettingsPanel); setIn.add(navigation); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = ((int) dim.getWidth() / 2) - 170; int height = (int) ((dim.getHeight() / 2) - 170); setIn.setBounds(width, height, 340, 340); setIn.setResizable(false); setIn.show(); setIn.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { // Exit the application setIn.dispose(); windowOpen = false; output.setText("process: settings frame CLOSED"); curWindow = 0; } }); } public void actionPerformed(ActionEvent e) { if (e.getSource() == sonarCM && cmOrIn == false) cmOrIn = true; else if (e.getSource() == sonarIN && cmOrIn == true) cmOrIn = false; else if (e.getSource() == reset && resetYOR == false) resetYOR = true; else if (e.getSource() == motorDG && dgOrRt == false) dgOrRt = true; else if (e.getSource() == reset && resetYOR == true) resetYOR = false; else if (e.getSource() == motorRT && dgOrRt == true) dgOrRt = false; else if (e.getSource() == keySubmit ) { up1Int = up1.getSelectedIndex(); up2Int = up2.getSelectedIndex(); down1Int = down1.getSelectedIndex(); down2Int = down2.getSelectedIndex(); left1Int = left1.getSelectedIndex(); left2Int = left2.getSelectedIndex(); right1Int = right1.getSelectedIndex(); right2Int = right2.getSelectedIndex(); space1Int = space1.getSelectedIndex(); space2Int = space2.getSelectedIndex(); shift1Int = shift1.getSelectedIndex(); shift2Int = shift2.getSelectedIndex(); } } } public class about extends JFrame{ /** * */ private static final long serialVersionUID = 1L; JButton Ok; about() { JAbout = this; JAbout.setTitle("About"); JAbout.getContentPane().setBackground(Color.WHITE); JAbout.resize(340, 340); JAbout.getContentPane().setLayout(panelsCenter); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = ((int) dim.getWidth() / 2) - 170; int height = (int) ((dim.getHeight() / 2) - 170); JAbout.move(width, height); Ok = new JButton("OK"); Ok.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e){ if (e.getSource() == Ok) { JAbout.dispose(); windowOpen = false; curWindow = 0; } } }); JAbout.getContentPane().add(Ok, "South"); JAbout.setVisible(true); JAbout.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { // Exit the application JAbout.dispose(); windowOpen = false; curWindow = 0; output.setText("process: about frame CLOSED"); } }); } } public TextField createMessage() { output = new TextField("Welcome to NXT Command Center 1.0.0!"); output.setEditable(false); output.setBackground(unEdit); output.setFocusable(false); output.setForeground(Color.RED); return output; } public TextField createS1(String text) { sen1 = new TextField(text, 30); sen1.setFocusable(false); return sen1; } public TextField createS2(String text) { sen2 = new TextField(text, 30); sen2.setFocusable(false); return sen2; } public TextField createS3(String text) { sen3 = new TextField(text, 30); sen3.setFocusable(false); return sen3; } public TextField createS4(String text) { sen4 = new TextField(text, 30); sen4.setFocusable(false); return sen4; } public Panel sensorsInput() { sensors = new Panel(new GridLayout(4,1)); sensors1 = new Panel(new FlowLayout(FlowLayout.LEFT)); s1 = new Label("Sensor 1:"); sensors2 = new Panel(new FlowLayout(FlowLayout.LEFT)); s2 = new Label("Sensor 2:"); sensors3 = new Panel(new FlowLayout(FlowLayout.LEFT)); s3 = new Label("Sensor 3:"); sensors4 = new Panel(new FlowLayout(FlowLayout.LEFT)); s4 = new Label("Sensor 4:"); sensors1.add(s1); sensors1.add(createS1("Sensor 1"), "North"); sensors2.add(s2); sensors2.add(createS2("Sensor 2"), "North"); sensors3.add(s3); sensors3.add(createS3("Sensor 3"), "North"); sensors4.add(s4); sensors4.add(createS4("Sensor 4"), "North"); sensors.add(sensors1, "North"); sensors.add(sensors2, "Center"); sensors.add(sensors3, "South"); sensors.add(sensors4, "South"); return sensors; } public TextField createM1(String text) { mot1 = new TextField(text, 30); mot1.setFocusable(false); return mot1; } public TextField createM2(String text) { mot2 = new TextField(text, 30); mot2.setFocusable(false); return mot2; } public TextField createM3(String text) { mot3 = new TextField(text, 30); mot3.setFocusable(false); return mot3; } public Panel motorsInput() { motors = new Panel(new GridLayout(4,1)); motors1 = new Panel(panelsLeft); Label m1 = new Label("Motor A:"); motors2 = new Panel(panelsLeft); Label m2 = new Label("Motor B:"); motors3 = new Panel(panelsLeft); Label m3 = new Label("Motor C:"); motors1.add(m1); motors1.add(createM1("Motor A"), "Center"); motors2.add(m2); motors2.add(createM2("Motor B"), "Center"); motors3.add(m3); motors3.add(createM3("Motor C"), "Center"); //info.add(m41, "North"); //info.add(m42, "Center"); motors.add(motors1, "North"); motors.add(motors2, "Center"); motors.add(motors3, "South"); //motors.add(info, "South"); return sensors; } public NXT_Command_Center() { //Create frame command = new Frame("NXT Command Center 1.0.0"); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = ((int) dim.getWidth() / 2) - 325; int height = ((int) dim.getHeight() / 2) - 225; command.setBounds(width, height, 650, 450); //Add Keylisteners and make it non-resizeable command.addKeyListener(this); command.setResizable(false); //Set the icon ImageIcon icon = new ImageIcon("icon_08.png"); command.setIconImage(icon.getImage()); //Create sensor inputs sensorsInput(); motorsInput(); createMessage(); command.add(sensors, "West"); command.add(motors, "East"); command.add(output, "South"); //Make it visible, and possible to exit. command.setVisible(true); command.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { // Exit the application System.exit(0); } }); } public static void main(String args[]) { System.out.println("Starting NXT Command Center 1.0.0"); new NXT_Command_Center(); } public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { case FORWARD: output.setText("process: UNABLE to complete command - Forward"); break; case BACKWARD: output.setText("process: UNABLE to complete command - Backward"); break; case LEFT: output.setText("process: UNABLE to complete command - Left"); break; case RIGHT: output.setText("process: UNABLE to complete command - Right"); break; case SPACE: output.setText("process: UNABLE to complete command - Space"); break; case SHIFT: output.setText("process: UNABLE to complete command - Shift"); break; case REPAINT: command.repaint(); break; case SETTINGS: output.setText("process: settings frame OPENING"); if (windowOpen == false) new settings(); else { output.setText("process: UNABLE to complete request - a window is already open"); if (curWindow == 2) setIn.requestFocus(); } break; case ABOUT: if (windowOpen == false) { new about(); windowOpen = true; curWindow = 1; } else { output.setText("process: UNABLE to complete request - a window is already open"); if (curWindow == 1) JAbout.requestFocus(); } break; case QUIT: output.setText("Good Bye!"); break; default: String kCode = Integer.toString(e.getKeyCode()); output.setText(kCode); break; } } public void keyReleased(KeyEvent e) { switch(e.getKeyCode()) { case FORWARD: case BACKWARD: case LEFT: case RIGHT: case SPACE: case SETTINGS: case SHIFT: case ABOUT: break; case REPAINT: output.setText("process: REPAINTED"); break; case QUIT: System.exit(0); break; default: output.setText("process: UNKNOWN command - " + e.getKeyChar()); break; } } public void keyTyped(KeyEvent arg0) { } } [/left][/left]
  13. Elnof

    Help

    The book explains how to use the leJOS API, not how to write in Java. I'm having trouble figuring out how to add a menu to a regulare Java frame. I know how to add one to a Jframe, but not to a regulare frame.
  14. Elnof

    Help

    Yea, I've bought the book about it. But that's not my problem, I'm having trouble with the making of the actual program. I understand the leJOS stuff.PS: Wrong link, thats for the stuff from 2002
  15. Elnof

    Help

    It's a Lego NXT, using the lejos firmware. Also, I have done some work, and I have new code, but it doesn't quite work. [b][size=2][color="#7f0055"] [left]import[/b][/color][/size][size=2] java.awt.event.*; [/size] import java.awt.*; import javax.swing.ImageIcon; public class NXT2 implements KeyListener{ /** * */ private static final long serialVersionUID = 1L; Color unEdit = new Color(211, 211, 211); final int FORWARD = 87, // W = forward BACKWARD = 83, // S = backward LEFT = 65, // A = left turn RIGHT = 68, // D = right QUIT = 81; // Q = quit TextField output; public TextField createMessage() { output = new TextField("Welcome to NXT Command Center 1.0.0!"); output.setEditable(false); output.setBackground(unEdit); output.setFocusable(false); output.setForeground(Color.RED); return output; } public NXT2() { //Create frame Frame command = new Frame("NXT Command Center 1.0.0"); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int width = ((int) dim.getWidth() / 2) - 300; int height = ((int) dim.getHeight() / 2) - 225; command.setBounds(width, height, 600, 450); //Add Keylisteners and make it non-resizeable command.addKeyListener(this); command.setResizable(false); //Set the icon ImageIcon icon = new ImageIcon("icon_08.png"); command.setIconImage(icon.getImage()); createMessage(); command.add(output, "South"); //Make it visible, and possible to exit. command.setVisible(true); command.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { // Exit the application System.exit(0); } }); } public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { case FORWARD: output.setText("process: UNABLE to complete command - Forward"); break; case BACKWARD: output.setText("process: UNABLE to complete command - Backward"); break; case LEFT: output.setText("process: UNABLE to complete command - Left"); break; case RIGHT: output.setText("process: UNABLE to complete command - Right"); break; } } public void keyReleased(KeyEvent e) { switch(e.getKeyCode()) { case FORWARD: case BACKWARD: output.setText("process: UNABLE to complete command"); break; case LEFT: case RIGHT: output.setText("process: UNABLE to complete command"); break; case QUIT: output.setText("Good Bye!"); System.exit(0); } } public static void main(String[] args) { new NXT2(); } public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } }[/left]
  16. Elnof

    Help

    Not that I know of... It might. But I'm not following, it's not the robot that paints the screen, it's the program I'm trying to make.
  17. Elnof

    Help

    Well, I could do that, but I think that I might be able to create a variable to gather the information... But the problem of repainting the screen still remains...
  18. Elnof

    Help

    Thanks for all the help. But I figured it out... Apparently Geocities forgot to mention that it costs to use PHP... Thanks for the help. Do you have any idea where I might be able to host PHP files for free?
  19. Elnof

    Help

    It's a program to controll a robot from your computer. And it will have fields where it displays the readings from the robots sensors. So, I would like the test to be constantly getting the information from the robot, and changing to suit the data. It might be considered dynamic content...
  20. Elnof

    Help

    I have a problem. I have a program I'm working on, and I'm not sure how I want to utilize the menu, and how to display constantly changing text... If someone could help me, I'd apreciate it!Here's my code: import java.awt.*;import java.awt.event.*;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JRadioButtonMenuItem;import javax.swing.ButtonGroup;import javax.swing.JMenuBar;import javax.swing.KeyStroke;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JScrollPane;import javax.swing.JFrame;public class NXT_control_center_1_0_0 {static JTextArea output;JScrollPane scrollPane;public JMenuBar createMenuBar() {JMenuBar menuBar;JMenu menu, submenu;JMenuItem menuItem;JRadioButtonMenuItem rbMenuItem;//Create the menu bar.menuBar = new JMenuBar();//Build the first menu.menu = new JMenu("File");menu.setMnemonic(KeyEvent.VK_A);menu.getAccessibleContext().setAccessibleDescription("The File Menu");menuBar.add(menu);//Connect or disconnect from icommandButtonGroup group = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Connect to icommand");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);group.add(rbMenuItem);menu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Disconnect from icommand");rbMenuItem.setMnemonic(KeyEvent.VK_D);group.add(rbMenuItem);menu.add(rbMenuItem);menu.addSeparator();menuItem = new JMenuItem("Quit",KeyEvent.VK_Q);//menuItem.setMnemonic(KeyEvent.VK_T); //used constructor insteadmenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));menuItem.getAccessibleContext().setAccessibleDescription("Quit the program");menu.add(menuItem);//Build second menu in the menu bar.menu = new JMenu("Motors");menu.setMnemonic(KeyEvent.VK_N);menu.getAccessibleContext().setAccessibleDescription("Change what buttons do what to the motors.");//Create Submenu for Wsubmenu = new JMenu("W");submenu.setMnemonic(KeyEvent.VK_W);//Submenu W for motor AButtonGroup wMotorA = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor A forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_A);wMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor A backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);wMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor A");rbMenuItem.setMnemonic(KeyEvent.VK_M);wMotorA.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu W for motor BButtonGroup wMotorB = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor B forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_;wMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor B backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);wMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor B");rbMenuItem.setMnemonic(KeyEvent.VK_O);wMotorB.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu W for motor CButtonGroup wMotorC = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor C forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);wMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor C backwards");rbMenuItem.setMnemonic(KeyEvent.VK_D);wMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor C");rbMenuItem.setMnemonic(KeyEvent.VK_R);wMotorC.add(rbMenuItem);submenu.add(rbMenuItem);menu.add(submenu);//Create Submenu for Asubmenu = new JMenu("A");submenu.setMnemonic(KeyEvent.VK_A);//Submenu A for motor AButtonGroup aMotorA = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor A forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_A);aMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor A backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);aMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor A");rbMenuItem.setMnemonic(KeyEvent.VK_M);aMotorA.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu A for motor BButtonGroup aMotorB = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor B forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_;aMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor B backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);aMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor B");rbMenuItem.setMnemonic(KeyEvent.VK_O);aMotorB.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu A for motor CButtonGroup aMotorC = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor C forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);aMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor C backwards");rbMenuItem.setMnemonic(KeyEvent.VK_D);aMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor C");rbMenuItem.setMnemonic(KeyEvent.VK_R);aMotorC.add(rbMenuItem);submenu.add(rbMenuItem);menu.add(submenu);//Create Submenu for Ssubmenu = new JMenu("S");submenu.setMnemonic(KeyEvent.VK_S);//Submenu S for motor AButtonGroup sMotorA = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor A forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_A);sMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor A backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);sMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor A");rbMenuItem.setMnemonic(KeyEvent.VK_M);sMotorA.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu S for motor BButtonGroup sMotorB = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor B forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_;sMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor B backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);sMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor B");rbMenuItem.setMnemonic(KeyEvent.VK_O);sMotorB.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu S for motor CButtonGroup sMotorC = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor C forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);sMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor C backwards");rbMenuItem.setMnemonic(KeyEvent.VK_D);sMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor C");rbMenuItem.setMnemonic(KeyEvent.VK_R);sMotorC.add(rbMenuItem);submenu.add(rbMenuItem);menu.add(submenu);//Create Submenu for Dsubmenu = new JMenu("D");submenu.setMnemonic(KeyEvent.VK_D);//Submenu D for motor AButtonGroup dMotorA = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor A forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_A);dMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor A backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);dMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor A");rbMenuItem.setMnemonic(KeyEvent.VK_M);dMotorA.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu D for motor BButtonGroup dMotorB = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor B forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_;dMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor B backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);dMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor B");rbMenuItem.setMnemonic(KeyEvent.VK_O);dMotorB.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu D for motor CButtonGroup dMotorC = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor C forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);dMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor C backwards");rbMenuItem.setMnemonic(KeyEvent.VK_D);dMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor C");rbMenuItem.setMnemonic(KeyEvent.VK_R);dMotorC.add(rbMenuItem);submenu.add(rbMenuItem);menu.add(submenu);//Create Submenu for Qsubmenu = new JMenu("Q");submenu.setMnemonic(KeyEvent.VK_Q);//Submenu Q for motor AButtonGroup qMotorA = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor A forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_A);qMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor A backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);qMotorA.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor A");rbMenuItem.setMnemonic(KeyEvent.VK_M);qMotorA.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu Q for motor BButtonGroup qMotorB = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor B forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_;qMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor B backwards");rbMenuItem.setMnemonic(KeyEvent.VK_K);qMotorB.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor B");rbMenuItem.setMnemonic(KeyEvent.VK_O);qMotorB.add(rbMenuItem);submenu.add(rbMenuItem);submenu.addSeparator();//Submenu Q for motor CButtonGroup qMotorC = new ButtonGroup();rbMenuItem = new JRadioButtonMenuItem("Motor C forwards");rbMenuItem.setSelected(true);rbMenuItem.setMnemonic(KeyEvent.VK_C);qMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("Motor C backwards");rbMenuItem.setMnemonic(KeyEvent.VK_D);qMotorC.add(rbMenuItem);submenu.add(rbMenuItem);rbMenuItem = new JRadioButtonMenuItem("No Motor C");rbMenuItem.setMnemonic(KeyEvent.VK_R);qMotorC.add(rbMenuItem);submenu.add(rbMenuItem);menu.add(submenu);menuBar.add(menu);return menuBar;}public Container createContentPane() {//Create the content-pane-to-be.dJPanel contentPane = new JPanel(new BorderLayout());contentPane.setOpaque(true);//Create a scrolled text area.output = new JTextArea(5, 30);output.setEditable(false);scrollPane = new JScrollPane(output);//Add the text area to the content pane.contentPane.add(scrollPane, BorderLayout.CENTER);return contentPane;}/*** 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("NXT Control Center 1.0.0");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Create and set up the content pane.NXT_control_center_1_0_0 demo = new NXT_control_center_1_0_0();frame.setJMenuBar(demo.createMenuBar());frame.setContentPane(demo.createContentPane());//Display the window.frame.setSize(650, 460);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();}});}}
  21. Elnof

    Help

    Number One Number TwoAlso, I found this bit of information on Geocities. What type of PHP are $_GET and include?Here
  22. Elnof

    Help

    Thanks for all the help, but I think that I'm just gunna scrap my Geocities site, and get my PHP files hosted by someone else...
  23. Elnof

    Help

    I don't see PHP code. In fact, I don't see anything at all: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD><BODY></BODY></HTML> Do you have a suggestion for different free web hosting that supports PHP?
  24. Elnof

    Help

    Thanks, but I still get a blank page. You sure that they support PHP?
×
×
  • Create New...