I am starting to learn java , If suppose we write a simple hello world program
class helloWorld
{
public static void main(String args[])
{
System.out.print("Hello World !");
}
}
And save this as test.java.Now after compiling it a helloWorld.class file is generated.But if we compile the same after adding "public" in front of 1st line, it throws error.
public class helloWorld
{
public static void main(String args[])
{
System.out.print("Hello World !");
}
}
but then changing the file name to the name of the class i.e. helloWorld.java, corrects the error.
I am making a simple text based game and i have a monster, and I am tring to make its health go down whent he user input "s" but istead it doesnt change and the users health even goes up.
Main.java
package exodus.game.main; import java.util.Scanner; import exodus.game.monsters.Nirav; public class Main { static String name; static String inputtemp;
So, Once again I'm attempting to make a Who Wants to Be a Millionaire GUI game. This is the actual game screen code
package WWTBAM; import java.awt.BorderLayout; public class GUIGame extends JFrame implements ActionListener { public static int moves = 0; public static boolean finished = false; public static boolean correct = true;
[Code] ....
When ever try and change the buttons text outside of the actual GUIGame constructor i can't. Like in the main method or the action listener.
The code won't work if you copy paste because it's a part of a larger package.
Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...
After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:
package com.mrgreaper; import javax.swing.*; public class MainWindow { private JPanel mainWindow; private JLabel playerlbl; private JLabel playerNamelbl;
[Code] .....
Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!
From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....
I tried adding a getter setter
public void setCharFirst(JLabel charFirst) { this.charFirst = charFirst; } in the MainWindow.class
Then i tried to set it from my main function
MainWindow.setCharFirst("test");
but it cant access it as my main function is static and it is not now can i make it static...
Every time I load a txt file into a JTextArea it prints the results to the JFrame incorrectly I notice its mainly the white spaces this is happening to. I have tried a few ways to remedy this problem but it still keeps occurring? I've tried append() read() also setText() even Scanner. I have enclosed a picture of my GUI and my txt file I am using.
I'm making a karaoke/DJ program for a DJ friend and one of the features she wants is the ability to change the pitch of a song (some singers ask for this).
I get a Base64Encoded image string (GIF format) from an external system. While reading the byte array and saving the image to file, the image gets saved in landscape orientation. The code snippet is below.
- from the main class will arrive three variable (String name_used, int level_choose, int level_result)
I have a .txt file with this kind of formatting:
mario 1 1 0 1 0 1 carlo 0 0 0 1 1 0 ...
Where I use 1 and 0 in the main for write if the level (you see that the numbers are always sixr? are egual to six level existing) BEFORE is done correct or wrong
- when in the main a user make a level a feedback coming back from the class level saying if the user made the count correctly or wrong. and i wanna replace the value (1 or 0) in the txt file with the new level result.
So i have all what i need as parameters i think.
name_used to look for the correct line in .txt file with .indexOf level_choosed to go throught the correct index of that line level_result (1 or 2) to be replaced with the existing one
Java Code:
public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{ } } mh_sh_highlight_all('java');
I have several different PopupWindows that i want to access from the same fragment. I would like for each PopupWindow to be it's own java file. Here is trimmed down code from an example showPopup.java file,
showPopup.java public class showPopup { //public class showPopup extends Activity implements View.OnClickListener{ //public class showPopup extends Window { public static Context appContext; PopupWindow popupWindow; SQLiteDatabase db; EditText edSpeciesLookup,edSpeciesLookupRowid;
[code]...
How do I configure inheritance to allow showPopup() class to reside in it's own Java file and be called from another class (file)? I've reviewed several hours of online resources as well as my reference books with no productive illumination. I've tried a number of possible implementations and extensions such as "public class showPopup extends Activity implements View.OnClickListener{...", and "public class showPopup extends Window.
1.) Is FileReader class the same as File Class. In my book it uses File class to read data from a file, but one of the members here used FileReader so I was wanting to know if it's identical function or not.
2.) When creating an output file, I will use
PrintWriter outputfile("hello.txt")
i just read a new topic of " appending data to a file," meaning if I want to preserve the old file I would have to use this. From my understanding all this does is prevents the old data from being deleted.
Now, in my code if I type ( "hello.txt",true)this would preserve the old data?
import java.util.Arrays; import java.util.Iterator; import java.util.ArrayList; public class Book { private String book; private String authorFirstName; private String authorSecondName;
[Code] ....
i don't understand, the above code generates an error saying that class book is publc, should be declared in a file called book.java. It is. And when the the public modifier is left out of the class it comiles but I then get a load of compile errors java.lang.noclassdefound error.
The compiler won't let me declare more than one class as "public". Am i correct in understanding that this is a java restriction ? This means i need to create a new file, for each public class that i want in a package ? The rest of the classes without access modifier will all be package-private. (Q has been asked before probably, but my search could not be narrowed).
I have got 2 classes in a source file, 1 real class and 1 test class with main() method. While executing with java command which class name should i write - real class or test class???
I am wanting to override certain methods in some Minecraft class files, and tell those class files to use code from my class files.
And no, I don't mean extend a class. When I try to extend from the main Block.Class, it makes that file as another block file for the game, or something.
So like, I want to tell the main file that handles block registries to use the code from my class file to register my custom blocks to the list of blocks, but without modifying that main block file.
Is this even something that's possible?
Also, I know that the way a file is named affects the loading order. My class files would be named using symbols to make it load right before the class file I want to override.
I am currently working on Java software which resize jpeg images and change DPI also. For JPEG images having app0JFIF node it works fine and the images new DPI is reflected in Photoshop. But if app0JFIF node not exist, I am trying to create a new one and set the DPI value there. Everything is going proper but if I open these images in photoshop it does not reflect new DPI but the size changes.
I am having hard time to grasp the concept of java as i am beginner. according to different sources found in internet, only one class is written in one source file. and all those class can be accessed through the main class. my question is
1.can we access one class present in one source file, through another class present in another source file [not through the class containing main method]?
2.can we create more than 1 class in same source file?is there special way to do it? i do get error always when i try to do so 3.can multiple classes contain main method? or should there be only single class containing it?
I'm trying to access class file which is inside the package and package is inside the jar file but I can't access that class file inside my source file . All files are on desktop .
I am trying to create a second class in a single java file (first time trying this) and want to use data from the first class in the second class but I am not able to do it. What am I missing :
package simplecommissioncalculation; import java.util.Scanner; // import java.util.Scanner public class SimpleCommissionCalculation { public static void main(String[] args) {