peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Can i use getTimeInMillis() to make sure end date is bigger than start date?

Exactly

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

GregorianCalendar inherits getTimeInMillis() method from Calendar class. Any ideas how you can use this to your advantage? ;)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I just quickly modified code that I found on internet

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.hwpf.extractor.WordExtractor;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class GeneratePDF {

    public static void main(String[] args) {
        String pdfPath = "C:/";
        String pdfDocPath = null;
        try {
            InputStream is = new BufferedInputStream(new FileInputStream("C:/Test.doc"));
            WordExtractor wd = new WordExtractor(is);
            String text = wd.getText();
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(pdfPath + "viewDoc.pdf"));
            document.open();
            document.add(new Paragraph(text));
            document.close();
            pdfDocPath = pdfPath + "viewDoc.pdf";
            System.out.println("Pdf document path is" + pdfDocPath);
        }
        catch (FileNotFoundException e1) {
            System.out.println("File does not exist.");
        }
        catch (IOException ioe) {
            System.out.println("IO Exception");
        }
        catch (DocumentException e) {
            e.printStackTrace();
        }
    }

}

Just keep in mind POI doesn't like "docx" format yet...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
try
		{
			System.out.println("Creating Users table with primary key index ... ");
			stmt.executeUpdate("CREATE TABLE Users ("
			                  + "userID TEXT(20) NOT NULL "
			                  + "CONSTRAINT PK_Users PRIMARY KEY, "
			                  + "lastName TEXT(30) NOT NULL, "
			                  + "firstName TEXT(30) NOT NULL, "
			                  + "pswd LONGBINARY, "
			                  + "admin BIT"
			                  + ")");
		}
		catch (Exception e)
		{
			System.out.println("Exception creating Users table: "
			                  + e.getMessage());
		}

		// Create UserStocks table with foreign keys to Users and Stocks tables
		try
		{
			System.out.println("Creating UserStocks table ... ");
			stmt.executeUpdate("CREATE TABLE UserStocks ("
			                  + "userID TEXT(20) "
			                  + "CONTRAINT FK1_UserStocks REFERENCES Users (userID), "
			                  + "symbol TEXT(8), "
			                  + "CONSTRAINT FK2_UserStocks FOREIGN KEY (symbol) "
			                  + "REFERENCES Stocks (symbol))");
		}
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Just create two separated classes that extends JPanel add necessary components as need it. Then display them depending on selected action in your JFrame.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Dunno about nice formatting, but hey you asked for it Apache POI - Java API To Access Microsoft Format Files

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Nice attempt, but post is 2 years old...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Javapassion.com holds free online courses taught by Sang Shin

These courses are free to take for anyone who wants to enhance their knowledge and programming skill on Java technologies.

What you waiting for??? ;)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Thanx John

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Ezzaral, AMetnik already made one post in regards of above issue yesterday, claiming above code is part of Applet (see here). Now this is creating confusion...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

But then we are back to beginning where I said there is no main() method in applet.
Secondly what sort of connection from applet to server? What sort of server (database, web or application server)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

i know, this is the server i am creating so i can get data from another server, since it would create policy errors if i tried to connect directly to another ip then the one i am loading the applet from :) thats what i have been told for sure? :-)

noone to help?

I guess not because above is confusing statement. You creating server????

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Yeah sorry forgot you using JTetxPane, keep ArrayList as String

To add element to ArrayList use add(Element) and to convert ArrayList to Array use toArray() method

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Correct answer.

Question for you: Are you sure you want to keep read in grades in String format, while you use their integer values for calculations? Wouldn't be better to have Array of integers rather then array of Strings?

As in regards of ArrayList, doesn't this look better

ArrayList<Integer> grd = new ArrayList<Integer>();
while(grades != -1)
{
	strGrades = JOptionPane.showInputDialog(null, "Please insert Grade");

	if (strGrades == null) finish();
		grades = Integer.parseInt(strGrades);
		totGrade = totGrade + grades; // add grade to total

	gradeCount = gradeCount + 1; // increment counter
}

then your limited size array?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Somewhere in that block that I marked you should have something like grd[i] = SOMETHING; where i represent next available position to be used

PS: You shouled really look into use of Collections like ArrayList as these makes your life easier. No need of size declaration, adding process will either add to end of the ArrayList or in specific position requested by your application logic

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
/*Yes you do declare and instantiate  array here*/
	String[] grd = new String [50];

	for (int i=0; i<=grades; i++)
	{
		while(grades != -1)
		{
			/*However do you store data retrieved from user somewhere in this section to array???*/
			strGrades = JOptionPane.showInputDialog(null, "Please insert Grade");

			if (strGrades == null) finish();
				grades = Integer.parseInt(strGrades);
				totGrade = totGrade + grades; // add grade to total

			gradeCount = gradeCount + 1; // increment counter
			/*End of section which I meant*/
		}

		for (int j=0; j<grd.length; j++)
		{
			doc.insertString(doc.getLength(), grd[j] + "\t", gradesPane.getStyle("regular"));
		} // end for loop to insert detail

	} // end for loop to initialize array
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have general flaw in the logic. The values collected by JOptionPane will never get out of your while loop. To add the values to array you need to add each new grade to array inside while loop.
Also I would suggest to use ArrayList instead of size limited Array, that way you do not have to worry about exceeding Array limit and always you can convert ArrayList to simple Array with help of API

PS: Above posted code will not compile because you use wrong array

// Method to sort Grades from Low to High
	public void sort(String tempArray[])
	{
		// Loop to control number of passes
		for (int pass = 1; pass < tempArray.length; pass++)
		{
			for(int element = 0; element < tempArray.length - 1; element++)
				if (tempArray[element].compareTo(tempArray[element + 1])>0)
				{
					swap(/*grd*/tempArray, element, element + 1);
				} // end if
		} // end for loop
		addTextToTextPane();
	}  // end sort()
BestJewSinceJC commented: very helpful in this thread... +5
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

For the start Applet hasn't got main() method as you know from console or GUI applications. Have look at The Life Cycle of an Applet and here you can learn more on Applets if it is what you are after...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I guess C or C++, possibly C# but not sure, would be more suitable as you can use them to reach and communicate with OS. Dunno about Perl

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Have look at this article of what you can do with out any additional tools/libraries/plugins. However if you after tool you may consider GeSHi (I think dani use it here or she use it in past) or check result of this search and perhaps you find something for your self

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Direct connection to database from JSP!!!!!!!!!!! :'( :'( :'(
Please have look at this sticky post JSP database connectivity according to Model View Controller (MVC) Model 2 to get general direction of how to do it right way

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

These rules are in place to stop any "clever" poster putting quickly together "tutorial", post it on his/her web site/blog and then simply link it from daniweb. In doing so you are killing discussion as people in general would not discuss any issues with your solution, beside that you redirecting from daniweb and in many cases it is to increasing traffic to your place (one of the common things)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Keep It Spam-Free rules states

Do not spam, advertise, plug your website, or engage in any other type of self promotion. To encourage open, unbiased (incentive-free) discussion, it is prohibited to refer to sites you own or are affiliated with outside of the Business Exchange category.

So if you wanted to help the OP you should explain it in your post instead of plug-in link to your webie.

Would be there anything else you want to clear about forum rules?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You asked how to do menu that you can reuse in first place. I showed you how it can be done, my only issue with it was I couldn't attach it to frame.
Now it is up to you if you will do anything with it or wait for some other answers.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Still no success in adding the menu bar. Have look at attachment see if you can work it out.

Basically to create custom menu bar I did as follows:

  • Create new Class as right click on directory, select New, select JPanel Form (this will open in designer view)
  • Select Source and change extends javax.swing.JPanel to extends javax.swing.JMenuBar
  • back to Design
  • In Inspector tab (if you have default IDE layout in left side down, bellow Projects, Files and Services) or Windows, Navigating, Inspector to open this tab. Here right click on Form Test and do Reload Form
  • After this you can see that JPanel changed to JMenuBar and by right clicking on it you can add only Menu

From this point onwards you are on your own or maybe somebody can help you add this JMenuBar to frame. I tried, but as you can see fro code no luck

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I guess somebody else will need to fill in this gap. I'm able to design my own menu bar with menus and menu items. However so far I did not figure out how to attach this custom menu bar to frame. There must by a way I'm just looking in wrong place...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Design specific class to hold only menu items and all it needs (action listeners) and just add it to frames as you need it. If you design it properly you will also able to add some menu items to specific menu sections on the go as you need or do you need code example?

BestJewSinceJC commented: Good suggestion :) +3
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

It is complaining it did not get all 12 parameters as declared in query. Do you have any sort of validation for entered data to handle empty fields?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Are you sure about that explanation mark "!" in your file path string? fr = new FileReader (new File("C:\\University Study\\Component Engineering\\Assignments\\Assignment !\\yourFile.txt")); Also if you just learning to work with files try to keep your file in same folder as your compiled program so then you do not need to call absolute path as above and can simple use relative just yourFile.txt

PS: You class name doesn't have proper name in according to recommended naming conventions which for class says the first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Please have look at this thread JSP database connectivity according to Model View Controller (MVC) Model 2 for database connectivity

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

As far as I know JavaScript is not able to access & communicate with any database directly. AJAX is able to do so, but then you would have to learn that. Why you want to connect from JSP to database through "side kicks" when you have at your hands full power of Java?

PS: If you insist on connection to be done by other technology, then this thread is in wrong section...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Writing to file in JAR archive is not possible, only reading is allowed. I'm not sure what you are doing, as what you trying to write/store, but you have generally two options

  1. Record Management System - RMS that is essentially mini database
  2. PDA Optional Packages is JSR 75 that late you use FileConnection object, but this is often used for remote access (URL/OBEX/Bluetooth)
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

As already stephen said you cannot pass JavaScript stored variables to another JSP.

PS: Would be nice if you start using full sentence English, as the above is against forum rules

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

If you share with us how you

designed a function dat reads the values from the checked fields n stores them in an array of variables

we may share with you how to pass it to next page

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You can do it in MIDlet, but I will say keep it in another class as that way your code would be easier to manage. Scrolling down hundred of lines is unpleasant sport

Ezzaral commented: Helpful posts in this thread! +19
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You welcome.
If you new to J2ME you may want to have look at this post here, that is specifically dealing with basics of J2ME in terms what you may need, where you want to look etc. Plus I made blog entry on How-To custom WTK NetBeans and IntelliJ IDEA that explains where to find and how to add Sony Ericsson, Nokia or others WirelessToolKits to NetBeans or IntelliJ IDEA.

PS: If your original question been solved, please kindly marked this post as solved by clicking on "Mark as Solved" below last post. Thank you

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Sorry, do not expect people to go through your whole code 400lines is lots of reading. You better tell us which method should throw IOException so we can get on with it...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You forgot to give it an instance to which the method should be called

Main kpge = new Main();
        KeyPair kp = kpge.generateKeyPair(999);
        PublicKey pubKey = kp.getPublic();

However with your current code you just complicating your life. Do it like this

public class Generator {
    
    public PublicKey getPublicKey() throws Exception{
    
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("DSA");
        SecureRandom rng = SecureRandom.getInstance("SHA1PRNG", "SUN");
        rng.setSeed(seed);
        keyGenerator.initialize(1024, rng);
        KeyPair kp = keyGenerator.generateKeyPair()
        PublicKey pubKey = kp.getPublic();
        System.out.println("-- Public Key ----");
        System.out.println("   Algorithm=" + pubKey.getAlgorithm());
        System.out.println("   Encoded=" + pubKey.getEncoded());
        System.out.println("   Format=" + pubKey.getFormat());
        return pubKey;
    }
}

When you call Generator method getPublicKey() make sure you do it inside try/catch statement and take care of any exceptions

PS: Please in mind I cannot guaranty that above code will work 100% as I just simplified code provided by you

darkagn commented: Another very helpful thread by you :) +4
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Your generator class should be ordinary class not the one with main() method in. Just simple calls with few methods that are called do some precessing and provide a return, something like

public class Generator{

    public Generator(){}

    public PublicKey getPublicKey(){
        KeyPair kp = kpge.generateKeyPair(999);
        PublicKey pubKey = kp.getPublic();
        System.out.println("   Algorithm=" + pubKey.getAlgorithm());
        System.out.println("   Encoded=" + pubKey.getEncoded());
        System.out.println("   Format=" + pubKey.getFormat());
        return pubKey;
    }
}

I did not included any import or try/catch statements, that is something you should be able to add.

PS: Are you working on something like this Nokia Digital signatures - PKIMIDLET example?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Little silly question. Did you try setMaximumSize(Dimension maximumSize) on JPanel?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I played around with your code and there is strange behaviour that I'm little baffled. I think that maybe somebody with depth knowledge of Java would be able to explain.
From your short code it is not clear why ever would you like to change text inside TextBox (I never need it to do so because of following). Under normal circumstances you will either pass text directly to TextBox constructor to be showed on the screen or collect text from this class. This class is normally placed on screen only accompanied by commands and does not really work in the same fashion as you may know TextArea or JTextArea in JSE that you collect data from one place and drop them in TextArea that is part taking in the GUI form. I think TextBox.setString(String) method will be deprecated with new release of Java Microedition.
So if you want to place any text into TextBox you need to do it in constructor TextBox(String title, String text, int maxSize, int constraints)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I have to tell you, yo are confusing me with jumping between MIDlet and traditional Java.
Can you again explain in detail what you doing as I do not see possible connection between MIDlet and console/GUI based application. You can have MIDlet to HTTP, Web Service or basic networking, but I never seen direct MIDlet to desktop application

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

In Generator.java

public int generateNum(){
    int number;
    //your process of generating random number
    return number;
}
//OR with argument
public int generateNum(int numArgs){
    int number;
    //your process of generating random number with use of numArgs
    return number;
}

in PKI.java

// somewhere in the coding
Generator generator = new Generator();
int randomNum = generator.generateNum();
//OR
int randomNum = generator.generateNum(10);    // generate number between 0 and 10
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Just provide public getter method as in any other Java coding and you are sorted, or create method that will have some return type if you need to pass arguments to generator

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

My apologies for late reply, but I had some problems with my pc which need it to be sorted before attending to your problem.

Your problems lays with use of packages that are not supported by Microedition. As you can see from JME API there is nothing such as java.security package as we know it from Java SE API. Therefore different approach is need it.

As I do not know full scope of your project I can only point you in general direction. Understanding MIDP 2.0's Security Architecture article by by Jonathan Knudsen would be best place to start.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I have Java How to Program 6th edition and I really like it. It takes reader from simple basic of console programming to GUIs, drawing, databases, web development (6th edition compare to 7th is missing on AJAX, but I prefer 6th explanation on JSP and servlets), networking and introduction to threads. Progress through book is followed by UML topics based on currently explained topic in the book. I never read the whole book I guess somewhere around 1/3 it was more of jumping between various topics because of my school teaching path, but I consider it as good learning resource plus attached CD is usually loaded with interesting things

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Compress your NetBeans project into ZIP file add at it as attachment to your next post. I will try to have look at it as soon as possible. But from above messages it seems you are missing some declarations of various types. Look like you did not merge these two projects properly

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I'm not sure if that is possible to do it directly on JFileChooser. Maybe somebody else would know more.
Option 2 would be create custom JFileChooser, see some examples here