peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Good, can you mark this as solved then?
There would be link bellow last post which read something like "Marks Solved"...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Http connection is very little different from classic java http connection. If we omit IOExceptions, code would look like this

String url = "http://www.daniweb.com";
InputConnection ic = (InputConnection)Connector.open(url);
InputStream in = ic.openInputStream();
// read from InputStream
ic.close();

For some examples check this place, also this book is very good resource

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

The second option will be easier for you.
Basicaly it is same as you have now, but you will add another dialog for pound amount to be add after stones dialog. Also you should apply some validating mechanizm to check if entered data are in valid form that you can process

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

1) you can make custom dialog that takes two variables instead of one
2) request stones with first dialog and then request pounds in second dialog and work with them

That is if I correctly interpreted the part "splitting up the "ans" so that i can just multiple the stones by 14 then add the pounds" as reading two variables and process them

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Connecting to DB with use of JSP is old fashioned and should not be used any more. So if you wish to interact with DB you should use JSP page with form for data entry, then pass it to servlet that will store data in DB and then to progress to futher action. Data validation can be done on JSP or servlet depends on your requirements and your abilities. For some tutorials you should check Sun website or see these tutorials

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

This is one of the question that is most unwelcomed here. For once it show lack of interest and creativity.

How are we supposed to pick up a topic for you if we do not have any background on your Java ability? Also if you took your time to browse this forum you would find there been many sugestion brought up for this matter.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Nice explanation is here

The JDK is a subset of what is loosely defined as a Software development kit (SDK) in the general sense. In the descriptions which accompany their recent releases for Java SE, EE, and ME, Sun acknowledge that under their terminology, the JDK forms the subset of the SDK which is responsible for the writing and running of Java programs. The remainder of the SDK is composed of extra software, such as Application Servers, Debuggers, and Documentation.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Have look at this tutorials they can be helpful. Also you should try to get your hands on O'Reilly book Java Servlet & JSP Cookbook. Has nice examples

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

There is javax.imageio as part of Java that you can use. However not always suficient for the task. You may want to consider Java Advance Imaging or even better Java Advanced Imaging Image I/O. Please take the note that this sugestions are good as far image resizing is done on the server. You would not be able to implement it on mobile device derictly!
There could be solution if you use Advanced Graphics and User Interface (AGUI) Optional Package for Java Platform, Micro Edition (JSR-209) or one of the custom libraries for 2D & 3D from companies like Nokia or Sony Ericsson but I did not try them yet.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have to be more specific about it...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

The Java Tutorials - String

Using String's static format() method allows you to create a formatted string that you can reuse, as opposed to a one-time print statement. For example, instead of

System.out.printf("The value of the float variable is %f, while the value of the " + 
                       "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);

you can write

String fs;
    fs = String.format("The value of the float variable is %f, while the value of the " + 
                       "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);
    System.out.println(fs);
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

To be more precise, post your code which you should have by now at least started. Point where you running into troubles and we will see what can be done about it

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

API for BufferedWriter it say it loud and clear

A newLine() method is provided, which uses the platform's own notion of line separator as defined by the system property line.separator. Not all platforms use the newline character ('\n') to terminate lines. Calling this method to terminate each output line is therefore preferred to writing a newline character directly.

so your code may look like this after transfer

import java.io.*;
import java.util.*;

class WriteTest
{
	public static void main(String[] args)
	{	
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
			out.write("aString");
			out.newLine();
			out.write("this is a");
			out.newLine();
			out.write("ttest");
			out.close();
		}
		catch (IOException e)
		{
			System.out.println("Exception ");		
		}
		
		return ;
	} // main ends here.
}; // the class ends here.

This however is sort of silly solution so you have to think how you gone approach it. You need to temporary store your strings in Vector or List and on the ned to loop it through and write to file

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

yeap JGoodies is another option. I used Substance for my final year project and like it. However I hope to try out JGoodies too

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Windows XP look&feel? Everybody know have that looks like. Try something new ! ! !

Come on try Substance

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Man!!!!
Why so many posts about something to which you have solution in my post?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Update in code marked with red colour. There is no method nextChar for Scanner !

//Calculate Program
import java.util.Scanner;

public class Calculate
{	
	public static void main(String args[])
	{
		Calculator calc = new Calculator();// new Calculator
	
		char selection;
		char yesNo;
		Scanner input = new Scanner(System.in);
		//This is the priming question. It starts the calculator and
		//should only run once.
		System.out.printf("Do you want to perform a calculation now?\n");
		System.out.printf("Select 'Y' for yes, or anything else for no.\n");
		yesNo = input.nextLine().charAt(0);
		
		//This while loop tests the initial answer. If user didn't enter 'Y'
		//then loop and program should terminate
		while(yesNo == 'Y' || yesNo == 'y')
		{
		
			//This section is where user selects type of operation
			System.out.printf("What operation would you like to perform?\n");
			System.out.printf("Enter '+' for add, '-' for subtract\n");
			System.out.printf(" '*' for multiply '/' for divide\n");
			
			selection = input.nextLine().charAt(0);
			
			//This inner loop tests for operation type. User must enter valid
			//response or loop won't end
			while(selection != '+' && selection != '-' && selection != '*' && selection != '/')
			{
				System.out.printf("You need to enter a correct character.+-*/\n");
				selection = input.nextLine().charAt(0);
			}
			
			//At this point, a valid operation should have been entered. This
			//section should call appropriate method for the operation
			if(selection == '+')
			calc.add();
			
			if(selection == '-')
			calc.sub();
			
			if(selection == '*')
			calc.mult();
			
			if(selection == '/')
			calc.div();
			
			//This section is the end of the first while loop. It gives user
			//the option to exit or perform another operation.
			System.out.printf("Do you want to perform another calculation\n");
			System.out.printf("Enter 'Y' for yes, or …
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

If you wish to get help with your code you better provide full code not just one class. Calculator class is missing.
By-the-way to insert code into post do not use INLINECODE tag, but press hash sign "#" in the post bar or just simple type CODE tags and place your code between these tags

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

you missing break after most cases in your switch statement

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Do you think that user of your application will be interested in reading your code and seting all variables by him self? Or do you think all variables are always initialized?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

@nschessnerd , you better test it before you submiting something or you may be providing wrong solution an waisting your and poster time...

import javax.swing.JOptionPane;

public class GPA {

	private double gpa = 0.0;
	private int classNum;
	private String gradeInput;
	
	public GPA() {
	}	
	
	public String UserInput(){
		gradeInput = JOptionPane.showInputDialog("Enter Grade:");
		return gradeInput;
	}
	
	public double inputGrade()
	{
		int end = 0;
	    for(classNum = 1; classNum <= 7; classNum++)
	    {
	    	gradeInput = UserInput();
	    	
	    	switch(Character.toLowerCase(gradeInput.charAt(0) ))
	    	{
	    		case 'q' :
	    			classNum = 8;	    			
	    			break;
	    		case 'a':
	    			gpa += 4.0;
	    			end = classNum;
	    			break;
	    		case 'b':
	    			gpa += 3.0;
	    			end = classNum;
	    			break;
	    		case 'c':
	    			gpa += 2.0;
	    			end = classNum;
	    			break;
	    		case 'd':
	    			gpa += 1.0;
	    			end = classNum;
	    			break;
	    		case 'f':
	    			gpa += 0.0;
	    			end = classNum;
	    			break;
	    		default:
	    			break;
	    	} // close switch	    	
	    	
	    }
	    return gpa/end;
	}
	
	public static void main(String [] args)
	{
		GPA runProgram = new GPA();
		System.out.print(runProgram.inputGrade());
	}
}

I understand that gpa should return everage mark so I ajusted calculation. If I'm wrong please corect it as necessary. The code bellow return gpa, so now you have to think how do you gone find if person had any "F" in the results

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

That basic you should already know

int newNum = Integer.parseInt(integerAsString)
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Above commands are what you need to use...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have to associate apropriate action with your Print button which will retrive all data from labels and text fields, then display them in text area

To collect your data use following methods
JTextField.getText() - will return string inside text component. The method is inherited from JTextComponent
JLabel.getText() - returns the text string that the label displays.

PS: Next time you realy need to give bigger images or provide binoculars to see these miniatures

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

thanks.I compiled it and it showed me like 32 errors in the whole program for example cannot find symbol variable/method. Thanks a lot though. Appreciate it.

That 32 errors are your mistakes while writing program, namy of them like this

inFieldPane.add(newJLabel("Given name"));

OK, bellow is working version of your program. I mayde some changes to program structure as do prefer create GUI on it own and then just simly call it from main. Also I will recommend to use some other layout manager then BorderLayout, which is not suitable in your case. Check out BoxLayout and GridBagLayout

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyNew implements ActionListener
{
	JTextField givenName;
	JTextField familyName;
	JTextField fullName;
		
	MyNew()		
	{		
		JFrame jfrm = new JFrame("Text Fields");
		jfrm.setLayout(new BorderLayout());
		jfrm.setSize(200, 200);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		givenName = new JTextField(10);
		familyName = new JTextField(10);
		fullName = new JTextField(10);
		fullName.setEditable(false);
		
		// Set first panel to retrive data from user
		JPanel inFieldPane = new JPanel();
		inFieldPane.setLayout(new GridLayout(2,2));
		inFieldPane.add(new JLabel("Given name"));
		inFieldPane.add(givenName);
		givenName.addActionListener(this);
		inFieldPane.add(new JLabel("Family Name"));
		inFieldPane.add(familyName);
		familyName.addActionListener(this);
		jfrm.add(inFieldPane,BorderLayout.NORTH);
		
		//Set second panel to submit data for processing
		JPanel submitPane = new JPanel();
		submitPane.setLayout(new FlowLayout());
		submitPane.add(new JLabel("Press button to enter names"));
		JButton submitButton = new JButton("Submit");
		submitButton.addActionListener(this);
		submitPane.add(submitButton);
		jfrm.add(submitPane,BorderLayout.CENTER);
		
		// Set third panel to display processed data
		JPanel outFieldPane= new JPanel();
		outFieldPane.setLayout(new GridLayout(1,2));
		outFieldPane.add(new JLabel("Full Name"));
		outFieldPane.add(fullName);
		jfrm.add(outFieldPane,BorderLayout.SOUTH);		
			
		jfrm.setVisible(true);
	}
		
	public void actionPerformed(ActionEvent e)
	{
		if(e.getActionCommand().equals("Submit"))
		{
			String fullString = familyName.getText().trim()+", " +givenName.getText(). trim();
			fullName.setText(fullString);
		}
	}
	
	public static void main(String[] args)
	{
		SwingUtilities.invokeLater(new Runnable()
		{ …
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

can you make those photos larger?

No need for it, if you will try that program you would understand what he is about....


GridLayout is not best solution for the layout you try to do. You should consider BoxLayout, GridBagLayout or combination of more then one. So if we look at first image you can split it on 3 main sections

  1. Labels, text fields, combobox and buttons in top part
  2. Text area from middle
  3. Two buttons from bottom

Then top part can be split on following

  • 3 text fields with their labels from left
  • text field with label from middle together with combo box(this can be also split but not necessary)
  • 2 buttons from the right

Hope that helps

iamthwee commented: Useful, well planned reply +11
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
command.executeUpdate("UPDATE Students SET Quiz1='"+sq1+"',Raw_Score='"+fD+"' WHERE stud_name='"+name+"'");

missing single quotes around fD

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

To avoid repeating previous sugestions I will ask. Did you sorted out problem with your original query that you posted in first place? Or that problem still remain?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

remove the double quotes
UPDATE Customers SET stud_name='+stdName+' WHERE stud_ID='45698'

You can do this only when you wish replace current value of stud_name with new value which will be stdName. However in this case stdName represent variable and not value so ivatanako approach is correct.

ivatanako can please post rest of your code in order to find the problem?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I think you need to read all posts not just the last one :)

What is the exact error that you are getting? Do you get it when you try to compile or when you run it?

I am currently using netbeans and the line that says "public class PayrollApp" gives me an error that says i have to define the class PayrollApp in another file.

My question is this. do i need to define it in another file. and if so what do i include?

(i am sorry, being new to this i may not be asking the question correctly)

I have no idea why Netbeans do this as your code is fine and will run on any other IDE without problems. You can try and remove public before class PayrollApp. If this doesn't help, please post exact error which you get from Netbeans

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
  • read the file line by line
  • split the read line on empty character
  • strings received this way store in your arrays
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Check permisions for your folder mckoi1.0.03 if they are setup properly (I asume you using Unix base system as you mentioned home directory).
Reconsider arrangement of path in your coding. If file and one and two are in same directory, file one need access to file two and you want to execet them from diferent directory. Then provide full path for execution for file one, but you do not need to do same for file two as it is called from same level.
If this doesn't help, I will have to ask you to provide parts of code to see what is going on...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Are you sure that you are on appropriate level from which give path is leading to mentioned files, or you in same directory as these files?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I think that File method listRoots() is your best shot. However I have no idea how this work if you have dual booting system in combinanion windows and unix

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

It is bad practice to connect to DB from JSP. JSP is not supposed to do so, it is Servlet what you should use. JSP should have minimum of Java coding inside it...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You missing main method. So either implement main method in your code or create another class with main method that will make use of yout Test6 class

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Not exactly what I had in mind. I do know how to create JAR and how to run it. What interest me is how you gone tell your application where to find JAR file which is inside your lib folder?

/lib/(other jar files your app depends on like JDBC dirvers,etc)

For instance I wish to include customize look&feel which is already compresed into JAR file and store in this lib folder.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I'm realy interested how this work also. Never did it before....
Would you mind Ezzaral to elaborate on the question? How exactly you point your application toward this JAR file?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Same mistake in both cases

  • you store user input into Department but compared variable is dept, I think you forgot to parse String Department to integer dept so whole time you run check on null value of dept int dept=0;
  • your last attempt iCez actually work once parse implemented
    if (dept<=3){
       System.out.println("You belong to: Mr.X");
       }else if (dept>=4&&dept<=7){
       System.out.println("You belong to: Mr.Y");
       }else if (dept>=8&&dept<=9){
       System.out.println("You belong to: Mr.Z");
       }
  • Another option is code bellow which also deal with number out of boundaries 1 - 9
import java.io.*;
public class Test5
{
	public static BufferedReader input=new BufferedReader (new InputStreamReader(System.in));
	public static void main(String args[])
	{
		String Department;
		int dept=0;
		try{
		System.out.println("Enter Department:");
		Department=input.readLine();
		dept = (int) Integer.parseInt(Department);
		}
		catch(IOException ioe) {}
		
		if(dept>7 && dept<10){
		System.out.println("You belong to: Mr.Z");
		}else if (dept>3 && dept<8){
		System.out.println("You belong to: Mr.Y");
		}else if (dept>0 && dept<4){
		System.out.println("You belong to: Mr.X");
		}
		else{
		System.out.println("Department not recognice");
		}
	}
}
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

So what you are saying is that I can simply include the database program with the rest of the software and the database program does not have to be installed on the computer as a seperate program.

You need to stright-up your facts... Lets put it this way.
Your application will work with database, but that does not mean it will not provide database program. Your program will provide a way to access this database and way to read/write/validate data from it. Database does not have to by instaled on the machine on which you run your program, but it have to have a way to access this database.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Have you imported java.util.regex.Pattern for Pattern and java.util.regex.Matcher for Matcher or at least imported java.util.regex.*? Defenetly not...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I do not know what your teacher gave it to you and if you already covered Exceptions, but that what you get when you use BufferedReader getLine().
Check this tutorial and you should be able to figure it out what to do with it. Main difference between yours code and code in the tutorials is that you read from command line and tutorial do it from a file

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

That is why NetBeans should be used once you learned more about Java and development in Java. NetBeans can be realy confusing...
I found some extra bracklets in your JSP file and here is updated version

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <title>Account information</title>
  </head>
  <body>
     <jsp:useBean id="fileBean" class="exampleprojects.FileBean"/>
    <%
    String topic =request.getParameter("topic");
    String vPath ="exampleprojects/"+topic+".txt";
    String filePath=getServletConfig().getServletContext().getRealPath(vPath);
    if(topic.equals("none"))
    {%>
        Please Select a topic.
    <%}
    else
    {%>
        <jsp:setProperty name="fileBean" property="file" value="<%= filePath %>"/>
        <% 
        if(request.getParameter("view")!= null)
        {%>
        <jsp:getProperty name="fileBean" property="data"/>
        <%}
        if(request.getParameter("post") != null)
        {%>
            <h2>Account Information</h2>
            <form action="interface.jsp" method="post">
                <TextArea name=message cols=25 rows=5></TextArea> 
                <input type=hidden name=topic value="<%= topic%>"><br>
                <input type =submit name=addBulletin value="post bulletin">                
            </form>
          <%}
          if(request.getParameter("addBulletin") !=null && !request.getParameter("message").equals(""))
          {%>
				<h2>Bulletin Saved!</h2>
                <jsp:setProperty name="fileBean" property="data" param="message"/>
                <jsp:setProperty name="fileBean" property="data" value="----------------------------------"/>
        <% } 
     } %>
               
                <br><br>
                <a href="interface.html">Return to main Page</a>
  </body>
</html>

You will now able to navigate from index.html to interface.hml and interface.jsp. However once you create new bulletin and want to view it, it will not be able to display as your bean is dealilng with FileReader that is supposed to create a txt, but I di dnot have time to get it working.

If you will have some problems to run this, just post bellow

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Hmmmmm interesting, I would never say that main method bellong to JSP...
...or is this new programming approach?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You forgot to put single quotes before and after double quotes on first inserted value vno

String vsql = "insert into employee values('"+vno+"','"+vname+"')";

That should sort your problem

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Please post your code so we can have look. When posting please use code tags [ C O D E ] [/ C O D E] and insert your code between them. Code tags are hidden under hash sign "#"

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

you really dont understand..

i am making a compiler.and not compiling

any 1 can help me to run the class generated??

No need to be harsh this way.

Your first post sound as english is not your first language and you do not provide a proper explanation. Secondly only beginners really put any code in "bin" folder as they can't or do not want to figure out how to set up PATH and CLASSPATH for Java.

Your question "any 1 know how to run the generated class file??" sounds like begginer call for help. I hope that you learn from your mistake and next time provide good explanation.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

This is error which I got from your code

Exception in thread "main" java.lang.NullPointerException
    at GameLogicClientHOPP.get(GameLogicClientHOPP.java:33)
    at LogicUI.run(LogicUI.java:18)
    at GuessingGame.main(GuessingGame.java:12)

Your get method has following return return in.readLine(); . readLine method of DataInputStream is deprecated and you should not use it, check here.
I have got no experience with Java and networks but I think you did not understand properly reading and writing from/to socket. This tutorial can be helpful, read here

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

If you can be more specific about "couldn't make it out", that would help us.
Also there is a post in this section with many Java tutorials by thekashyap, here

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Your problem is line 128 and 167 where you declare and initialize these objects with null value. It will be relatively fine if you use these objects just inside your else if statements and provide proper values for them, but not in your case when you use them later on outside these statements.
So declare your objects along with other variables (line 93 - 95) and then you can initialize them later in your code.

PS: You will have to sort few other errors in order get this working