This program consists of a function in one class. It demonstrates the "Left To Right" Principle used by most of the languages.
and12 commented: thanks for tips +1
This program consists of a function in one class. It demonstrates the "Left To Right" Principle used by most of the languages.
i am running this midlet on sun wireless toolkit 2.5.5. i can create many objects of same midlet from that toolkit ....
Hello,
Firstly, read the rules before you post. You should post code inside the CODE tags.
Im not sure what you mean by creating objects from toolkit, Problem could be that toolkit do not create new object everytime. Its just passing you the reference of Object created on first time.
You can check it by simply adding " System.out.println("Checking") " to constructor. If "Checking" is printed only one time on Console.
Regards,
Firstly,
@peter_budo, Mind your language! This isnt your home street, Where you can use any cheap words.
If you read my reply with open eyes ...
"Hello,
I think the problem is... "
That means, Even im not sure about it and Im trying to help him according to my knowledge. If im wrong, then please correct even ill be glad if you help me and guide me to understand something new.
But you are just NOT allowed to say anything bad or abusive here. You are moderator here, So please act like a moderator and a teacher and seniors for others.
And about the demo (scenario), Im trying to help him according to his scenario and the logic he has made. Iknow its a bad code. But the thing is, A programmer whos unable to understand how to use Image and ImageItem, How can you be sure that he will be able to understand the help you provided him ? If hes not sure what hes doing in basic part and not able to recognise the problem, He will be able to understand the advance of it ?
Regards,
I want to create a custom NumberFormat which returns empty string for negative values and the double number iteslf for +ve and zero values. Please guide me....................
Hello,
This is for you.
public class CustomNumberType extends Number{
public double doubleValue() {
return 0;
}
public float floatValue() {
return 0;
}
public int intValue() {
return 0;
}
public long longValue() {
return 0;
}
}
Implement your logic in this class.
Regards,
I seem to have a problem displaying an image from the phone's filesystem in J2ME.
The following code works for images that are in the res folder but not if the path references to a file on the filesystem ..
path = "file:///C:/Data/Images/200908/25082009004.jpg";
try {
image = Image.createImage(path);
} catch (IOException e) {
e.printStackTrace();
}
imageItem = new ImageItem(null,image,ImageItem.LAYOUT_CENTER,"Imag e not found");
form.append(imageItem);Do I need to use an inputStream ?
If so, how ?
Hello,
I think the problem is with Image path. loading image from drive isn't supported by J2ME (because theres no drives in mobile) or the image path is incorrect.
Also, theres no need to create ImageItem object, you can append Image directly.
Regards,
public void commandAction(Command command, Displayable displayable) {
if(command==exit)
{
destroyApp(true);
notifyDestroyed();
}
else if(command==start)
{
try
{
recordstore=RecordStore.openRecordStore("My RecordStore",true); // LINE 1
}
catch(Exception error)
{
alert=new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
String outPutData[]={"Mary","Bob","Adam"};
for(int x=0;x<3;x++)
{
byte[] byteOutPutData=outPutData[x].getBytes();
recordstore.addRecord(byteOutPutData,0,byteOutPutData.length);
}
}
catch(Exception error)
{
alert=new Alert("Error Waiting",error.toString(),null,AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
byte[] byteInputData=new byte[1];
int length=0;
for(int x=1;x<=recordstore.getNumRecords();x++)
{
if(recordstore.getRecordSize(x)>byteInputData.length)
{
byteInputData=new byte[recordstore.getRecordSize(x)];
}
length=recordstore.getRecord(1,byteInputData,0);
}
alert = new Alert("Reading", new String(byteInputData, 0,length), null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
catch (Exception error)
{
alert = new Alert("Error Reading", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
recordstore.closeRecordStore();
}
catch (Exception error)
{
alert = new Alert("Error Closing", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
if (RecordStore.listRecordStores() != null)
{
try
{
recordstore.deleteRecordStore("MY RecordStore"); // LINE 2
}
catch (Exception error)
{
alert = new Alert("Error Removing", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
}
}
}
Check "Line 1" and "Line 2" tags.
"My RecordStore" and "MY RecordStore" both are different names.
Theres no RS with name "MY RecordStore". Thats why its showing error.
Regards,
Hello,
Study on File , ByteArrayInputStream, ByteArrayOutputStream, DataInputStream and DataOutputStream classes of java.io package. This is all you have to do. If you do a smart search, You will get code for this program as its really common.
use listFiles() method of java.io.File class to get list of all files in a specific folder.
For more info on java.io package
Regards,
Okay, but when I override paintComponent, it gives me an error...
It works if I don't override paintComponent (as in it doesn't throw any errors, but nothing is painted...)... why's that?
Code (The class that is having problems, the other class calls init and start game)
package server; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import game.*; import javax.swing.*; import java.awt.*; /** * Write a description of class Linker here. * * @author (your name) * @version (a version number or a date) */ public class TestGame implements PlugNPlayIMPL{ JPanel gamePanel; public TestGame(){ init(); } public void startGame(){ gamePanel = new JPanel(); while(true){ gamePanel.repaint(); } } public void endGame(){} public void testPaint(Graphics g){ if(g==null) { System.out.println("THESE GRAPHICS HATE YOU AND YOUR FAMILY!!!"); return; } g.fillRect(35,35,200,200); } public void init(){ gamePanel = new JPanel(){ public void paintComponent(Graphics g){ super.paintComponent(g); testPaint(g); } }; } public static void main(String[] args){ try{ Runtime.getRuntime().exec("rmiregistry", null, new java.io.File("I:\\RMI_Server")); PlugNPlayIMPL game = new TestGame(); PlugNPlayIMPL stub = (PlugNPlayIMPL) UnicastRemoteObject.exportObject(game, 0); Registry reg = LocateRegistry.getRegistry(); reg.rebind("TestGame", stub); System.out.println("Bound Game Object."); }catch(Exception e){ e.printStackTrace(); } } public void loadSplashScreen(){} public JPanel getGamePanel() throws RemoteException{ return gamePanel; } }
Error:
java.lang.ClassCastException: cannot assign instance of $Proxy1 to field server.TestGame$1.this$0 of type server.TestGame in instance of server.TestGame$1
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2032)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1212)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1953)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy1.getGamePanel(Unknown Source)
at client.LoadGame.main(LoadGame.java:32)
at client.__SHELL3.run(__SHELL3.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native …
Hello,
Please post the code related to the problem so we can check and help you on it.
Still...
You are using JPanel.getGraphics() to get the Graphics object to draw on. You should be drawing only within the paintComponent() method using the graphics object supplied as the argument.
Hope this can help you.
Regards,
Hi Thanks For The Reply...
i already used that,But its not worked.....If There any other solution to solve this,.,.,
double amt = ((10000.0+3000.0)*(30.0/100.0));
System.out.println(amt);
Working fine.
Output : 3900.0
if still not working, Please post the code related to the problem.
Hi To All,
I have an equation in string like this
((BASIC+HRA)*(30/100))
Using replace function
Now i replaced this into values...
String formula = ((10000+3000)*(30/100))whole thing as a string now 'Formula'...
How can i calculate this formula
float amt = formula;
Now i have an error...type casting....i can't calculate this amt
float amt = Float.parseFloat(formula);
and btw why are you storing equation result in string ?
better way :
float amt = ((10000+3000)*(30/100));
Regard,
Hello again,
Sorry for late reply, I was out of town.
Ok, I will be posting 3 programs in few time.
1 - Snake
2 - Snake and ladders
3 - Web browser
Also, I have another question to ask.
I have just released my first open source project. Its an Object Relational Mapping Framework for java application.
I just made a start of it. I have future plans for it but before proceeding i want to make sure, im on the right way or not. Also, Im new to sourceforge.net too, So i need little help on it.
It would be the best if anyone can try my framework and check it.
Waiting for your suggestions.
Regards,
Greetings,
Hmm, Im not sure Is this the right place to ask this question, Well If im wrong please correct me.
Im working in a company as Java programmer that also provide professional training for Java and two of my trainees have created "Stick Snake" and "Snake and ladders" game in java (these 2 games for now, Many more to come).
And, I want to share that code with newbies so they can read and understand the code and build up their logic tech. I found Daniweb the best place for it.
So what i want to know is, How can i share those codes ? You cant say those codes are fully optimized or best codes as codes are written by trainees and even i haven't checked them, I have just seen games in working condition.
So please let know, Should i post them in "Code Snippets" area or just provide links of files here ?
Regards
A way to add rows to JTable :
// Header
Object[] col = new Object[]{"Col1","Col2"};
// Data
Object[][] data = {}; // Blank
DefaultTableModel model = new DefaultTableModel(data,col);
JTable table = new JTable(model);
// OR
table.setModel(model);
// Adding Rows
model.addRow(new Object[]{"Data1","Data2"});
Hope this will help you.
Well, Im not sure what you meant by comparing images.
If you are trying to compare images based on pixels colors then you can use getPixelColor method of Robot class.
getPixelColor(int x, int y)
Returns the color of a pixel at the given screen coordinates.
but still it will be a memory-consuming process to compare images using this way.
Regards,
Actually what I said is what I believe to be best practice. In general, you can do whatever you want.
But I doubt if anyone will write an entire application using only unicode. Can you imagine?
LOL, We will need to develop a special application to read and write applications in that such way. ;)
No you shouldn't use unicode for declaring methods and variables.
You use unicode for unsupported characters. If your keyboard has the 'a' then use it for the name of your method. What's the point to use unicode then
Yes, Thats what i actually wanted to say.
Thanks for help!
Thanks for reply,
Ok, Got it.
So can we say, we use unicode in comments, method names and variable names to create a better documentation in native languages?
Or is there any other reason too ?
Hello,
I just discovered that we can use unicode anywhere in the program.
EG :
public class CheckUnicode {
public static void m\u0061in(String\u005B\u005D args) {
System.out.println("Hello World!");
}
}
\u0061 = 'a' .. \u005B = ''
This program will execute fine without any errors.
But what i want to know is, Whats the benefit of using unicode in program ?
Waiting for your views and suggestions.
Regards,
Hi. My problem i guess it is simple but i guess I'm simple as well :). The problem is the flowing: I have a JTextFead and a search method for IDs. The IDs are 7 char long. I want to be able when the user enters 7 chars the search method to be invoked. My first idea was a focus listener and a if statement if the chars are 7 then search, but that requires the txf to lose focus and on the regain then it searches. My other idea was to detect key events but niter is a good idea I guess =/.
Hello,
Key event will work fine from my point of view.
On every key event you can check if the length of value in JTextField is equal to 7.
Example :
if(jTextBoxObj.getText().length() == 7){
doSearch();
}
Regards,
thnx alot ..it worked ....when i decrypt the word become the plain text and without spaces ..thank you very much ...
i still have some questions :S but i'm embaressed to ask you ..:S
lol, Its ok, I will be glad to help you. :D
Regards,
hi ,,,can you please give me an answer for my question ....and thnx in advance
Hello again,
Its really simple, Just write a if statement inside the loop to check (p == ' ') . If the condition returns true then skip that char and set encryptedtext variable to ' ' (SPACE) instead of doing the calculation.
If you still cant get it, Please let me know.
Regards,
Hello,
Firstly, Please post your code inside the [ CODE ] [ / CODE] tag.
There are many problems with your code and you really need to do hard work on it.
Its not a big deal to solve your programming mistakes but the thing that matters is, you will be able to understand those changes or not ?
So i suggest you to understand these topics first:
Defining Methods : http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html
String Concatenation : http://www.java-samples.com/showtutorial.php?tutorialid=217
Best of luck!
Hello,
Heres another way to read the file:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class TestURLReading {
static protected void readURL() {
String u = "http://afterextratime.net/game/ita/1/Laz.txt";
URL url;
InputStream is;
InputStreamReader isr;
BufferedReader r;
String str;
try {
System.out.println("Reading URL: " + u);
url = new URL(u);
is = url.openStream();
isr = new InputStreamReader(is);
r = new BufferedReader(isr);
do {
str = r.readLine();
if (str != null)
System.out.println(str);
} while (str != null);
} catch (MalformedURLException e) {
System.out.println("Invalid URL");
} catch (IOException e) {
System.out.println("Can not connect");
}
}
static public void main(String args[]) {
readURL();
}
}
Tested and working perfectly.
Regards,
Hey again,
Ok, got you. First of all, 7 + 5 = 12 so it should be 'M' LOL :P
Here the solution, Change the formulas to :
Encryption : 65+(((int)e-65) + key)%26
Decryption : 65+(((int)p-65) - key)%26
Tested, Working fine and according to the table.
Input Word : HELLO / Encrypted Word : MJQQT
Regards
Hello,
I think, the problem is in the encryption and decryption formula. I tried to find it out by googling on it. But i didn't get anything related to the formula that you are using.
So can you please post the encryption and decryption formula here ? and a test calculation.
Let Key = 5 and word to encrypt = 'hello'
Regards,
Hey again,
I got the answer. Word that you want to encrypt must be entered in UPPERCASE.
Or if you dont want to restrict user to enter word in only uppercase, then use toUpperCase() method (on encryption action) and toLowerCase() method (on decryption action) of String class.
Regards,
Hello,
I think, the problem is in the encryption and decryption formula. I tried to find it out by googling on it. But i didn't get anything related to the formula that you are using.
So can you please post the encryption and decryption formula here ? and a test calculation.
Let Key = 5 and word to encrypt = 'hello'
Regards,
Please how to get a specified data from a file?? in java
and what is the substitution of the seek function in java???
I need information
Thanks
Hello,
Lesson : Basic I/O
http://java.sun.com/docs/books/tutorial/essential/io/index.html
File I/O : To manipulates files.
File I/O Streams : To read and write.
Next time, Please do good search in forum and on Java docs website before posting.
Regards,
Hey,
Please post your code related to problem, so we can check and help you :P
Regards,
hi,
i am useing the netbeans for the first time n i am trying to connect to a MS Access DB through the wizard but i am
not able to.I entered for a DSNless connection:
Name:JDBC-ODBC Bridge.
Driver: sun.jdbc.odbc.JdbcOdbcDriver
Database URL: jdbc:odbc: Driver={Microsoft Access Driver (.*mdb)};dbq=C:\Users\Vamsi\Documents\PIN.mdb;
the issue its giving is: Unable to add connection. Cannot establish a connection to :jdbc:odbc: Driver={Microsoft
Access Driver (.*mdb)};dbq=C:\Users\Vamsi\Documents\PIN.mdb; Using sun.jdbc.odbc.JdbcOdbcDriver[Microsoft][ODBC Driver
Manager]datasource name not found or no default driver specified)for a connectionwith DSN:
i entered the same deails except for the URL i gane the name of DB-i.e PIN
I have also created a System DSN of the name PIN.mdb in the Contol panel > Administrative tools > Data sources(ODBC).
but its giving the error of cannot retrive the schema.
i am not able to determine whats the default Uid and pwd for an Access DB.please help me if i am missing something or hve done something wrong.
Hey Sandhya,
Im not sure about NetBeans because i never tried it.
About connecting to MS Access using DSN. Then the default username and password is blank, But if you want there should be some username and password then you can set it by clicking "Advance" button while creating the DSN.
Regards,