I am new to the java computer programming world. i am having basic trouble making the statement full and complete. i am trying to get it to say "The speed of the car is <answer> ft/sec" i have tried reading in the my programming book from school but it doesn't tell me how to fix it. the errors I am getting :
I'm writing a java program in eclipse of a tic-tac-toe game. I have to create it using JTextField's only I'm having trouble where the JTextField will only accept one letter and will only accept X and O is there any particular way to do this I started off with this piece of code
String text=tf1.getText(); if(text.length()>1) { System.out.println("this is not allowed"); tf1.setText("");
But it doesn't work so is there something I'm missing....
I'm new to java and up until now whenever I have created an object it has been via the BlueJ interface. I would make an object manually and then manipulate it with my methods.
I have made a basic program which adds objects into arraylists via the BlueJ interface. However I now need to prompt a user to enter a string which should create the specific object and add to its ArrayList.
Is there a way to create objects without manual specifying the parameters? I can provide some of my code if it is needed I am trying to make a crude version of Plant vs Zombies for an assignment.
I am aware of the scanner class but I only know how to prompt a user but I feel like if I can figure a way to create the objects I can dynamically I can associate the string inputs to the proper arraylists.
I'm creating a small program to count the number of mouse clicks the user is inputting into a BlankArea for a school assignment. I just finished with making the program look nice and all so I was putting in a MouseListener to detect the clicks. However, when I tried adding a MouseListener to the code, the error in the title appeared.
Java Code:
import javax.swing.*; import java.awt.*; import javax.swing.border.*; import java.awt.event.*; public class CountClick { JTextArea textArea = new JTextArea();
[Code] ....
Here's what's going on:
Compiling causes error as described in Title Java Code: createAndShowGUI() mh_sh_highlight_all('java'); cannot be referenced from a static context appears Java Code: public static void main(String [] args) mh_sh_highlight_all('java');
It contains the thread safe and program previously launched without mouse functionality(program appeared when there were no MouseListener components and thread safe had all static method stuff).
I would like my application to execute a command in cmd. The command looks like
start "" /D "C:Riot GamesLeague of LegendsRADSsolutionslol_game_client_sln elease s .0.1.55deploy" "League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 95.172.65.26:8088 P3hNrXYZlaM3iJ9ximtzJWHbwLhvbimJ 953089676 EUN1"
So my question is how do I do this?
I tried this, (just copy paste the command):
package MyProject; import java.io.IOException; import java.io.InputStream; public class Cmd { public static void main(String[] args) { try { final Process process = Runtime.getRuntime().exec("start "" /D "C:Riot GamesLeague of
I have a Java application this application sits on a Dedicated server and gets information about the machine and run commands on the machine.
I need it so that i can run these commands from pressing buttons on a website. For example i press a button to retrieve CPU info, it goes to the app, and the app sends the CPU info back.
I'm fine with the website and app its just the middle bit. How do i get the app to run commands sent from a webpage. Been ratting my brains for a couple weeks now.
For a shool assignment i have to create a java irc client. which responds to commands. the !SENDMSG command has two parameters !SENDMSG <username> <the message>.
i can get the username and the message seperated, but i would like to create a check in case someone gives a bad command like: !SENDMSG" " <-- note te extra spaces, or if someone gives only 1 parameter.
i m working on the SMS receiving using AT Commands using JAVA. i m getting the message of one page correctly using AT commands, but as i increase the size of SMS as 2, 3 or bigger pages the alphabets are converted to some thing like this
What I'm supposed to be doing is making it so the program can accept multiple filter and sort commands at one time, and each should be separated by a whitespace.I was thinking about parsing the input again, using whitespace as the delimiter, then normally progressing with each token, as though there was only one command.
However, coding this the way I'm doing it will firstly probably take hours, and secondly, it's likely not even right. I don't have any real way to determine which token contains which data from the Song objects.These are the specific requirements for this portion:A sort/filter command consists of one or more of the following options:
-year:<year(s)>
-rank:<rank(s)>
-artist:<artist>
-title:<title>
-sortBy:<field>
Any number of these options may be given, and they may be given in any order. If multiple options are specified, they will be separated by whitespace.
GazillionSongs Class (the main) Java Code: import java.util.*; import java.io.*;
my task is to add a few functions to an example calculator. I managed to add a divide button but I simply can't figure out how to add a working Pi and reciprocal function.
package newjavaproject; import java.awt.*; import java.awt.event.*; import java.applet.*; public class CalculateurNC extends Applet {
Why I am getting errors for this program I (tried) to write. I am new to java.
import java.util.Scanner; public class TheBarkingLot { public static void main(String args[]) { int n; Scanner input = new Scanner(System.in); System.out.println("How many large dogs are boarding today?");
im considered quite the "javanoob" as my account name states..The assignment is to basically take a number that is entered by a user, and based off what they type in, display a corresponding grade letter. For example, if they enter a number between 90-100, they should receive a response that they received an "A". Now, this is fairly simple using an if/else statement, but my professor wanted us to implement this, using a switch case to teach us the difference.
import java.util.*; public class SwitchTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
System.out.println("Please enter a number to find out what letter grade you have recieved");
I moved some static html pages I was hosting from apache into tomcat. (no point in running two servers) This works as expected, but I'm having trouble with the authentication part. In apache the authentication was handled by htaccess. I tried various tutorials on the web about configuring basic authentication in tomcat using WEB-INF/web.xml in tomcat, but I'm not sure this approach applies to static html pages. Using basic authentication for static html in tomcat?
My code is supposed to give the array index on the left and what is inside the array on the right, but i get nothing except the header? I am using eclipse.
public class Options{ public static void main(String args[]) { System.out.println("Index Value"); int value[] = {1,2,3,4,5}; for(int add = 0 ; add <value.length ; add++) { System.out.println(add + " " + value[add]); } } }
I am new to programming so for loops are a little confusing to me still but basically what I am doing is making a small java rpg game and I want to add in a time element to it so your character gets things like promotions and such after a certain amount of time playing.
for (int x = months; x < 12; years++) { for (int y = weeks; y < 4; months++) { for (int z = days; z < 7; weeks++) { for (int j = hours; j < 24; days++) { for (int k = minutes; k < 60; hours++) { } } } } }
That's what I have so far but I am getting a logical error/ infinite loop when I run. I have added each unit of time as a static variable so there's no problem there.
how I would go about having a moving sprite on a page, such as a virtual pet kind of thing. I've tried searching for it through the years and I've tried it with what I know on my own, but things just act up every time. Either:
A.) The sprite moves (respondent to key strokes, of course), but leaves a trail of its image behind itself.
B.) The background image writes, but for some reason the second image does not write, or is lost behind the background.
I'm sure these are simple issues for most of you, but I've tried going about this for a while now with no luck. What I'm trying to do I'm trying to write a virtual pet game, and I would eventually love to make it move around randomly like an A.I. that's pathfinding, but I've got ideas about that, just I need to know how to make it move period first, everything else I think I could figure out on my own.
I am setting up a standalone JNDI and loading a Datasource to the JNDI. DataSource I use is:
org.apache.commons.dbcp.BasicDataSource
The JNDI is set up as follows
String detectorHost = InetAddress.getLocalHost().getHostName(); System.out.println("detectorHost: " + detectorHost); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); final NamingBeanImpl namingInfo = new NamingBeanImpl(); namingInfo.start();
[Code] ....
I get the following exception
javax.naming.CommunicationException [Root exception is java.io.NotSerializableException: org.apache.commons.dbcp.BasicDataSource] at org.jnp.interfaces.NamingContext.bind(NamingContext.java:677) at org.jnp.interfaces.NamingContext.bind(NamingContext.java:611) at javax.naming.InitialContext.bind(Unknown Source) at com.lombardrisk.reform.integration.ReformIntegration.createJNDIServer(ReformIntegration.java:93)
[Code] ....
I don't quite follow why I am getting a NotSerializableException exception, this is a local JNDI in the same JVM and not a remote JNDI. Not sure why this occurs.
Here is the outline of what the program should do: [URL] .....
So far I've got the very basics in place, I can't really figure out ptplot despite trying to research it online. The only other thing I know is that arrays are not to be used (initially I intended on using them). Here's my code:
//The next line imports the java.io package import java.io.*; //Imports math language import java.lang.Math; //import ptolemy.plot.*; //Sets up class public class cp5 { //Declares class method called 'main'.
I am currently working on a application for a car park system. It uses GUI created by myself and holds 15 parking spaces. The user has the option to add, delete or search for a specific car. When the user adds a new car, details of the car are entered, the cars registration number (saved as a string), and the user had to check one raido button if the car is expensive, large or normal.
Once this information is entered a new instance of a vehicle will be created and the bay the car is allocated to turns green and stored in one of three arrays(expensive, normal or large). I also have a fourth array for creating the parking spaces.Each array can only hold 5 vehicles apart from the fourth which can hold all 15. When searching for a vehicle the user enters the registration of the vehicle they want to find, but I have to search through all three arrays to find it, and if it does not exist showing a message saying so.These are my three arrays
public static ParkingBay[] regularBays = new ParkingBay[5]; public static ParkingBay[] largeBays = new ParkingBay[5]; public static ParkingBay[] expensiveBays = new ParkingBay[5];
String Registration; - saves registration entered from add form String RegistrationNumber; - saves registration number from search form
I need to search to see if RegistrationNumber is in either of the three arrays if not show a message saying otherwise