|
Hi All...
Thanks for your help...
Ive had the .setTime line removed from the code and will test it..
I'm not sure why the extra lines of code were added in there.. it does seem a little convoluted way to achieve sending of a date/time value, but if it works, I'm happy...
Thanks heaps for pointing me in the right direction..
Regards
|
|
|
|
|
Hello Friends
I am using some images as background in my application.I want when I send that jar file to someone else then I dont need to send that files with jar file.So,where do I need to add my Images?In which Folder Do i need to add them so that while creation of jar file they also get bundle into it.I m using Netbeans6.7.1
I googled but not any proper anser found.
Any Ideas??
Thanks & Regards
Yogesh
|
|
|
|
|
Hey Guys
I found the solution.First Create a image folder in src folder.Then go to Project properties in Netbeans.Select Library,Add jar folder and then add that Image folder.And after that
Here is the code below:
URL myurl = Thread.currentThread().getContextClassLoader().getResource("Images/Logo.jpg");
ImageIcon im = new ImageIcon(myurl);
Anyway,thanks who viewed my Question.
Very fast starting on Monday At Work
Regards
Yogesh.
|
|
|
|
|
Hi guys,
I've got an issue here. I've created an application in Java that uses the DatagramSocket and DatagramPacket classes to send the byte array of data through the UDP protocol.
On the other hand, I'm trying to experiment using an Visual Basic application to receive the sent byte array of data.
However, I'm not sure whether if the received data is the correct one. How do I verify the data?
I'm using both the applications in windows PC, so there's is'nt a need to decode in Big Endians format.
I'm sending the byte array of data in different sizes. I've tried to output the sent data in String format in Java.
This is what I get:
eg.
byte[] data = s.getBytes();
System.out.println(data)
where s is a string variable that holds the converted byte arraydata.
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
pohcb_sonic wrote: How do I verify the data?
Well only you can answer that. You know what the data is, what format it is in, whether it is character (MBCS or Unicode) etc. So add some code at either end to check that you receive what you expect. Maybe precede each UDP packet with a length word so the receiver knows how many bytes it should receive, add a check digit at the end etc., etc.
pohcb_sonic wrote: I've tried to output the sent data in String format in Java.
This is what I get:
You showed the Java code but not the results.
It's time for a new signature.
|
|
|
|
|
The messages sent is displayed in hexadecimal format and at the same time, sent in bytes through the java application.
The code is as follows:
public void Display_Msg(int SIZE){
String S;
int DisplayLen = 0;
if (SIZE > txtSpd.getColumns()-1){
for(int i = 0; i< txtSpd.getColumns(); i++){
S = Integer.toString(ByteConversion(byteTxtMsg[i]), 16) + " ";
txtSpd.append(S);
}
txtSpd.append("\n");
for(int j = txtSpd.getColumns()-1; j< SIZE; j++){
S = Integer.toString(ByteConversion(byteTxtMsg[j]), 16) + " ";
txtSpd.append(S);
DisplayLen = txtSpd.getLineCount();
}
txtSpd.append("\n");
}
if (SIZE <= txtSpd.getColumns()-1){
for(int i = 0; i< SIZE; i++){
S = Integer.toString(ByteConversion(byteTxtMsg[i]), 16) + " ";
txtSpd.append(S);
DisplayLen = txtSpd.getLineCount();
}
txtSpd.append("\n");
}
if (DisplayLen > 18){
txtSpd.setText("");
}
String dat1="";
byte Msg[] = new byte[50];
for (int k = 0; k<SIZE; k++){
dat1 = Integer.toString(ByteConversion(byteTxtMsg[k]), 16) + " ";
}
Msg = dat1.getBytes();
try{
udpC.send(Msg);
}
catch (IOException w){
System.out.println("Error: " + w);
}
}
udpC is the instance object of the UDPConnect class involved in the declarations of DatagramPackets and DatagramSockets.
the Send method in udpC class is called.
Following is the sending portion of send method in the UDPConnect class:
public void send(byte[] data) throws IOException {
if (data.length > 8192) throw new IOException("Too much data");
DatagramPacket dp = new DatagramPacket(data, data.length, remote, port);
ds.send(dp);
}
So far, the connection and receiving portion of my application in VB has no problems. The problem now is the decoding of the message portion, whereby the decoding of the messages received seems to be different from what I've send through in the Java application.
The sending and receiving of the messages is in bytes. Could it be that sending portion of the messages in bytes in Java has something to do with this, as it is known that the bytes in Java has some restrictions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
modified on Monday, June 14, 2010 8:47 PM
|
|
|
|
|
pohcb_sonic wrote: Could it be that sending portion of the messages in bytes in Java has something to do with this, as it is known that the bytes in Java has some restrictions?
I'm not aware of any restrictions in this area. You say the decoding gives a different message form the sender, but if you are sending the raw bytes of the source message there should not be any need for decoding. Just ensure that the receiver understands the exact format of the data it is reading.
It's time for a new signature.
|
|
|
|
|
Hello Friends
I am adding a BackGround image to JPanel in two ways but It is not resizing according to JPanel.
First I added the Image to JLabel and then I added tht Label to Panel but after googling I found tht If we are adding through Label then only borderlayout take care of resizing and I tried all options of resizing but no use.
Then,Second I tried by creating a new class implements through JPanel.here is the code below:
class BackgroundPanel extends JPanel
{
Image image;
public BackgroundPanel()
{
try
{
image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("c:\\Logo.jpg"), "Logo.jpg"));
}
catch (Exception e) { }
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
if (image != null)
g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
}
}
With this method then i created the object like this
JPanel panel = new BackGroundPanel();
And added to ContentPane but with this method no Image is coming in background.
Any Ideas Please.
Thanks & Regards
Yogesh
|
|
|
|
|
What does this comment mean in your code above:
I don't see where you are handling this exception. If you get any sort of exception while loading the image, you just swallow it and carry on regardless.
|
|
|
|
|
Ok David,thx for ur advice.
But what abt resizing of image?
Thanks
Yogesh
|
|
|
|
|
I'm not a Swing programmer, so take this advice with a large, large pinch of salt.
Reading the documentation for Graphics, it looks as if drawImage is overloaded. The javadoc for the drawImage method you are calling says:
Draws as much of the specified image as has already been scaled to fit inside the
specified rectangle.
In other words, it does not resize the image.
There is another drawImage method that says:
Draws as much of the specified area of the specified image as is currently available,
scaling it on the fly to fit inside the specified area of the destination drawable
surface.
It sounds to me as if this is what you want.
My advice would be to read the documentation on how to draw and resize images. Sorry I can't be more help, but as I said, I am not a Swing programmer.
|
|
|
|
|
Thanks A Lot David for ur Advice.
I am also learning and learned a lot from CodeProject and still learning...
Thanks Anyway.
Regards
Yogesh
|
|
|
|
|
Hi
I am curious if some can help me with adjusting the height of a drop down once the user has selected a response that was wrapped.
I have a few pictures to show the drop down.
First one is as you would encounter it.
http://public.me.com/wcmedic/Closed.png
Second one is list expanded note option 5 is wrapped text
http://public.me.com/wcmedic/Expanded.png
Third is option 5 selected and note that it is cut off now
http://public.me.com/wcmedic/Cutoff.png
Thank you in advance
Rick
my email is wcmedic@live.com
|
|
|
|
|
Sorry Rick, but no-one is liekly to e-mail you.
The pictures are pretty but a little code snippet would help. I don't know if you're aware of this, but most people using this site are programmers rather than graphical designers
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thank You,
Unfortunately I know nothing about programming I am only doing the design. I was just being told by the programmer that what I was asking could not be done so I only wished to verify from some other sources.
I do appreciate your response, have a great day.
Rick
|
|
|
|
|
This is an assignment I'm trying to solve. I'm still fairly new to java and would like some assistance, if anyone is willing. Please ignore the modelAnswer() class, and focus on the getStudentAnswers. I was having trouble extracting chars from the array, and tried to use a switch statement instead.
For the moment our lecturer hasn't introduced Java GUI's and I've just used JOptionPane so far.
Please feel free to email me suggestions
/**
*
*Create a program to mark a set of multiple choice test results. This is *a console program
*
*that uses JOptionPane dialog boxes as well.
*
*Read a set of ten correct answers useing JOptionPane dialog box and *store the entire answer
*
*as one string in one variable. There are no spaces between the letters *and the user may
*
*enter capital or small letters. Here's is the sample input box:
*
* JOptionPane.showInputDialog("Please enter the answers to the ten *multiple choice questions
*
*\nno spaces and all in Capital letters e.g. ABCDEABCDE");
*
*
*Extract each letter from this string and fill an array with 10 letter *answers. This is done
*
*in a method loadAnswers after the above. When the answers have been *written to the array,
*
*display the following confirmation box.
*
*
*JOptionPane.showConfirmDialog(null, "The information has been saved.");
*
*The program must then ask the user for the number of students to *process as shown below:
*
*
*JOptionPane.showInputDialog("Please enter the number of students :");
*
*Thereafter the program must prompt the user for a student name and *thereafter for the
*
*student's 10 answers. Use Input Dialog boxes to achieve this. The 10 *answers for the student
*
*must be saved in another array.
*
*JOptionPane.showInputDialog("Please enter the student name");
*
*Please ensure the wording in the dialog boxes is shown in the figures *above.
*
*After successful capture of the marks, show another success *confirmation dialog box as shown
*
*in the second figure above. Thereafer compare the student's answers *with the answers in the
*
*answer array. Keep a count of the number of answers from the student's *record that match the
*
*answers in the answer key.
*
*Store the student's name and the number of correct answers in another *array(s).
*Calculate the symbol based on the following table:
*
*SCORE GRADE
*
*9-10 - A Above Average
*8 - B Above Average
*7 - C Above Average
*6 - D Above Average
*5 - E Below Average
*0-4 - F Below Average
*
*
*For each student, display the student's name and the number of correct *answers and a symbol
*
*(letter grade). Calculate the average number of correct answers for the *class and report it
*
*in a format similiar to the one on the next page.
*
*Example:
*
*Jean 10 A
*Jack 7 C
*George 9 A
*Paul 5 E
*Steven 7 C
*Jackie 6 D
*Susan 0 F
*Greg 8 B
*Gabby 8 B
*Andrea 9 A
*
*Using the array of student records, display a list of all students. *Report if a student had
*
*an average, above average with the number of correct answers shown *below.
*
*To end the program display a dialog box asking the user for *confirmation of exit as shown
*
*below.
*
*JOptionPane.showConfirmDialogBox
*
*
*Generally you are required *to
*
*1. Follow good programming practices
*2. Add appropriate comments.
*3. You must use methods and appropriate parameter passing.
*4. Use variables, class and method naming standards.
*
*
*
*
*
*
*
*
*Project Name: Student Marks System
* Developer: Code Scribbler
* Date: 6 June 2010
* Aim: To store test marks of multiple students and
* display their Aggregates, including the symbol
* scored (e.g. Name: George Mark: 9 Symbol: A)
*
* Contact: madpoet19@gmail.com
*/
import java.util.*;
import javax.swing.*;
public class Question1 {
public static String modelAnswer;
public static String studentName;
public static String studentAnswers;
public static int ansPosition01;
public static int ansPosition02;
public static int ansPosition03;
public static int ansPosition04;
public static int ansPosition05;
public static int ansPosition06;
public static int ansPosition07;
public static int ansPosition08;
public static int ansPosition09;
public static int ansPosition10;
public static int numOfStudents;
public static int nameCount;
public static int answerCount;
public static int nameSize;
public static String[] arrNameOfStudent = new String [numOfStudents];
public static String[] arrStudentAnswers = new String [numOfStudents];
public static void main(String[] args) {
modelAnswer();
getStudentAnswers(studentName, studentAnswers, nameCount, answerCount);
}//end main
public static void modelAnswer()
{
modelAnswer = JOptionPane.showInputDialog("Please enter the answers to the ten multiple choice questions \nno spaces and all in Capital letters e.g. ABCDEABCDE");
int init1;
int init2;
init1 = modelAnswer.indexOf(" ");
init2 = modelAnswer.indexOf(" ", init1 +1);
//System.out.println("Answers: " + modelAnswer.charAt(0) + " " + modelAnswer.charAt(init1 +1) + " " + modelAnswer.charAt(init2 +1) + " ");
//return modelAnswer();
}//end modelAnswer
public static void getStudentAnswers(String studentName, String studentAnswers, int nameCount, int answerCount)
{
numOfStudents = Integer.parseInt(JOptionPane.showInputDialog("Please enter the number of students :"));
char caseSymbol;
String finalSymbol = "";
String finalResult = "";
int questionScore = 0;
double questionScoreAvg = 0;
for (nameCount = 1; nameCount < 11; nameCount++)
{
studentName = JOptionPane.showInputDialog("Please enter the student name:");
Arrays.fill(arrNameOfStudent, studentName);
for (answerCount = 1; answerCount < 11; answerCount++)
{
studentAnswers = JOptionPane.showInputDialog("Please enter " + studentName + "'s answer for Question " + answerCount);
Arrays.fill(arrStudentAnswers, studentAnswers);
if (answerCount == 1)
{
ansPosition01 = studentAnswers.indexOf(" ");
caseSymbol = studentAnswers.charAt(1);
switch (caseSymbol)
{
case 'A':
questionScore = (questionScore +1);
break;
}//end switch statment
}//end if
else if (answerCount == 2)
{
ansPosition02 = studentAnswers.indexOf(" ", ansPosition01 +1);
caseSymbol = studentAnswers.charAt(2);
switch (caseSymbol)
{
case 'B':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 3)
{
ansPosition03 = studentAnswers.indexOf(" ", ansPosition02 +2);
caseSymbol = studentAnswers.charAt(3);
switch (caseSymbol)
{
case 'C':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 4)
{
ansPosition04 = studentAnswers.indexOf(" ", ansPosition03 +3);
caseSymbol = studentAnswers.charAt(4);
switch (caseSymbol)
{
case 'D':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 5)
{
ansPosition05 = studentAnswers.indexOf(" ", ansPosition04 +4);
caseSymbol = studentAnswers.charAt(5);
switch (caseSymbol)
{
case 'E':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 6)
{
ansPosition06 = studentAnswers.indexOf(" ", ansPosition05 +5);
caseSymbol = studentAnswers.charAt(6);
switch (caseSymbol)
{
case 'A':
questionScore = (questionScore +1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 7)
{
ansPosition07 = studentAnswers.indexOf(" ", ansPosition06 +6);
caseSymbol = studentAnswers.charAt(7);
switch (caseSymbol)
{
case 'B':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 8)
{
ansPosition08 = studentAnswers.indexOf(" ", ansPosition07 +7);
caseSymbol = studentAnswers.charAt(8);
switch (caseSymbol)
{
case 'C':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 9)
{
ansPosition09 = studentAnswers.indexOf(" ", ansPosition08 +8);
caseSymbol = studentAnswers.charAt(9);
switch (caseSymbol)
{
case 'D':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
else if (answerCount == 10)
{
ansPosition10 = studentAnswers.indexOf(" ", ansPosition09 +9);
caseSymbol = studentAnswers.charAt(10);
switch (caseSymbol)
{
case 'E':
questionScore = (questionScore + 1);
break;
}//end switch statment
}//end elseif
if (questionScore == 0 || questionScore == 1 || questionScore == 2 || questionScore == 3 || questionScore == 4)
{
finalSymbol = "F";
}
else if (questionScore == 5)
{
finalSymbol = "E";
}
else if (questionScore == 6)
{
finalSymbol = "D";
}
else if (questionScore == 7)
{
finalSymbol = "C";
}
else if (questionScore == 8)
{
finalSymbol = "B";
}
else if (questionScore == 9 || questionScore == 10)
{
finalSymbol = "A";
}
if (questionScore > 5)
{
finalResult = "Above Average";
}//end final result if
else if (questionScore < 5)
{
finalResult = "Below Average";
}//end final result elseif
questionScoreAvg = (questionScoreAvg + questionScore);
System.out.println(studentName + "\t" + questionScore + "\t" + finalSymbol + "\t" + finalResult);
}//end inner loop
questionScoreAvg = (questionScoreAvg / 100);
System.out.println("\n" + "\n" + "The class average is: " + questionScoreAvg);
}//end outer loop
}//end getStudentAnswers
}//end class
|
|
|
|
|
CodeScribbler wrote: Please feel free to email me suggestions
1. Read the forum guidelines[^].
2. Do not post your entire program, people tend not to have the time to try and figure out the whole thing.
3. Put your code between <pre></pre> tags - see the "code block" button above the edit window. To fix your question just edit the original, don't repost the question.
4. Don't use general questions, try and narrow down the problem to a specific area of code and then explain what is going wrong and what you think should happen.
It's time for a new signature.
|
|
|
|
|
Sorry for the long winded ramble. My apologies, I've included an easier to read snippet below. I would like to know am I extracting chars from the array, in the correct manner? How would I print an array to show the all the students in a single process?
for (nameCount = 1; nameCount < 11; nameCount++)
{
studentName = JOptionPane.showInputDialog("Please enter the student name:");
Arrays.fill(arrNameOfStudent, studentName);
for (answerCount = 1; answerCount < 11; answerCount++)
{
studentAnswers = JOptionPane.showInputDialog("Please enter " + studentName + "'s answer for Question " + answerCount);
Arrays.fill(arrStudentAnswers, studentAnswers);
if (answerCount == 1)
{
ansPosition01 = studentAnswers.indexOf(" ");
caseSymbol = studentAnswers.charAt(1);
switch (caseSymbol)
{
case 'A':
questionScore = (questionScore +1);
break;
}
}
else if (answerCount == 2)
{
ansPosition02 = studentAnswers.indexOf(" ", ansPosition01 +1);
caseSymbol = studentAnswers.charAt(2);
switch (caseSymbol)
{
case 'B':
questionScore = (questionScore + 1);
break;
}
}
|
|
|
|
|
CodeScribbler wrote: am I extracting chars from the array, in the correct manner?
Not sure I can answer that as I cannot quite figure out what you are trying to do here. I will say that your switch statements inside the if blocks do not make much sense. I think you probably need to spend some more time looking at the basics of Java, specifically the if, switch statements etc.
It's time for a new signature.
|
|
|
|
|
Thanks for the help Richard. I spoke to my lecturer and he helped me re-think the program's logic using pseudocode. I also realized that I left out the 'default' part of the switch statement, which is another reason why my program failed to run correctly.
Thanks for your time
|
|
|
|
|
You're welcome, good luck!
It's time for a new signature.
|
|
|
|
|
In a class I have private type variables. I'm writting a new clone method inside that class because I want a deep clone object for that class.
So I wrote private variable name.clone() before add it to the main clone object. System is giving 'The method from the type Object is not visible' error.
Can you tell is there any way to do deep clone?
Thanks in advance.
Regards,
Janaki
|
|
|
|
|
The method clone() is already defined on Object as being protected which is why you cannot call it in this case. How you clone your name variable depends on its object type. My guess is that it's probably a String. Since Strings are immutable you can just copy it to the new cloned instance.
|
|
|
|
|
I called clone() method only.. It has given me the above mentioned error. Even for Arraylist also its giving the same.
Thanks.
|
|
|
|
|
Just to be clear about this: you are saying that when you call clone() on java.util.ArrayList you get a compilation error, "The method clone() from the type ArrayList is not visible". Is that what you are saying? That sounds rather odd to me.
Perhaps you could post a small snippet of code which illustrates your problem.
|
|
|
|