peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Hey!

My problem is that I can't modify the "File name" label / text field programatically where you write the file name of your file in the JFileChooser.

If I want to have "Write your file" written in the file name (by default) field how would I manage to do that?
I can't find a method that let's me modify that field/text field....I hope u understand and can help me with that problem.

Question is unclear you better to elaborate more on it and/or support it with some screen shot.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Would you mind to share this solution with us?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Depending on what you using to read from browser/GUI application and which language you using Java/C#/PHP...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have to have installation of Java and Tomcat on your machine. Tomcat should be setup either as in this simple example or this more specific way. Then have look at first deployment.
To learn more about Java and web development have look at these resources:

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Is there something wrong with JSP database connectivity according to Model View Controller (MVC) Model 2 that is at the top of JSP section, you can view it here

stephen84s commented: I guess you should highlight and decorate that thread so that its more visible +6
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Vicky as stated before this is related to CSS plus JavaScript and has nothing to do with Java Server Pages

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I just made some small changes to your code:

  • initialized variables
  • moved calculation block out of while loop
import java.util.Scanner;			// Needed for the Scanner class
import java.text.NumberFormat;		// Needed for number format class

public class Movie 
	
{
	// Create a Scanner object to read input.
	static Scanner keyboard = new Scanner (System.in);
	
	public static void main(String[ ] args)
	
	{
		boolean cinema = true;			// Needed to apply master loop.
		boolean validInput;				// Needed to apply initial loop.
		boolean fullday;				// Needed to apply initial loop.
		boolean list = true;			// Needed to apply secondary loop.
		boolean decision=true;			// Needed to apply secondyloop.
		boolean yesno = true;			// Needed to apply secondary loop.
		
		NumberFormat nf = NumberFormat.getNumberInstance( );	// Defines the number format.
		double adult = 8.25;			// Stores the adult ticket price.
		double day = 0.0;				// Stores the day time ticket price.
		double children1 = 0.0;			// Stores the children ticket prices.
		double children2 = 0.0;			// Stores the children ticket prices.
		double total1 = 0.0;			// Stores the total cost.
		double total2 = 0.0;			// Stores the total cost.
		double total = 0.0;				// Stores the overall total cost.
		int atickets = 0;				// Stores the number of adult tickets.
		int ctickets = 0;				// Stores the number of child tickets.
		int enter = 0;					// To hold the movie choice.
		int capacity = 0;				// The total theater capacity.
		String answer = null;			// To hold an answer to the first Yes or …
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

The above question doesn't really specifies what you trying to achieve, but JFileChooser is something you should have look at, here is tutorial.
If this is not what you looking for, well then you need to provide more in detail description of you trying to achieve.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

i don't want to use iTex ... most of the methods described above are not working :(

iText is working fine as long you know how to use it not like brett.
iText tutorials, don't forget to download the library file and store it in your project folder

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

We know that books are expensive and everybody by nature like to save every penny especially in this bad economic all over the world.
So this few links can help you save few pennies

Just be warned these are only Limited preview so sometimes you may not be able to access some sections, similar to Safari service A Programmer's Guide to Java™ SCJP Certification: A Comprehensive Primer, Third Edition

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I still may have some problems with explaining some terms so I rather will provide a link and hope that can help you. From SCJP Sun Certified Programmer for Java 6 Study Guide.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Would be nice if you can post your solution as it may help somebody in the future.
Also please mark this post as solved.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Post move to JavaScript, dunno why it was posted in JSP (Java Server Pages) section...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Wouldn't be Timer more efficient?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Tomcat - The Definitive Guide should help you solve this. Here is a link from google book search for legal electronic copy. Chapter 2 is what you want to have look at

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

There are many of books, I hope you have deep pockets
I second javaAddict on learning Java first, however I have few reservation against learn it from NetBeans website as there some version conflicts (many of tutorials been created under version 5.0 or 5.5 and may kick of variety of porting errors when tried under 6.5, plus there are some other changes in IDE layout that will leave you in search of some menu options that may not even exist in newer version)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I think you do not understand what you want to do. System.out.println() are system calls you placed there for some reason by programmer (in this case by you, and you may not complitelly understand them). If you want to threat data handled by system calls differently you have to tell us if you wish to store them (file read/writing), show them to user in different form (GUI or just simple dialogue po-ups) or you do not wish to see any warning messages from your system in console.
So please explain your self as above doesn't make any sense...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Yes, it is cool side, but I see no reason to spam around the forum without reason...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Here is interesting list of tutorials

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Is that pre-requirement of your assignment or you just do not know how to read text file?
Have look at BufferedReader.readLine()

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have code, but it is in C#.
Why don't you convert it to Java and then ask specific question of any issues you may face?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You said you want to set text. However you did not said where do you get the text from, is it retrieved correctly and where you want to set it (obviously to text area, but did you try it?)
For these we need some code samples.

PS: To avoid any unnecessary haste have look at JTextArea.append(String) method and let us know if you got it working. In case it does not, please provide your latest code

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Code, code, code is what we need. Reading from magic ball is out of date....

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I did not look into iText for last 2 years. Did they extend the scope of documents that can be converted? As far I can remember it was only images gif, png, bmp, tiff, wmf and jpeg (there was problem with JPEG2000 - type of grey colour), html, txt, rtf, xml. Are you sure you can convert office formats like doc, ppt or xls to pdf?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Ehmmm where do I find this in Java Microedition? :?:

Neither me. For now I work in JME, Swing or Web Development so no.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Problem is we do not have full image. You are just feeding us with bits of information and we try to help you to our best knowledge. If you give us whole image that will make difference...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Rather then having tabbedPane.addTab("tab",new ScrollPane(new JTextArea()),null); you should go as

JTextArea jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);
tabbedPane.addTab("TAB_NAME", jsp);

in doing so you can either call jta directly if from same class or provide appropriate setter and getter methods for access from outside class.

I'm not sure if there is way to get names of all visible tabs, but to get name of currently selected is very simple tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Nothing to bless. You dealing with database connection from view, JSP document, that is bad thing to do. Ever heard of MVC Model2?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I'm not sure what Firefox you using, but my one is up-to-date and I have no problem to see this effect. It is not exactly the programmable drop down as you tried to do but it does the job

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

"Mark as Solved" bellow last post...

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

If you check this tutorial you should be able to find answer to your question

stephen84s commented: :P There you go advertising your thread again +5
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I made few changes so have look at it

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.text.DecimalFormat;


public class MorgageCalculator extends JPanel{

	//global variable
	private JComboBox IntRates;
	private JLabel prinlb, rateLb, termLb, paymtLb;
	private JButton calBtn, resetBtn;
	private JTextField prinTxFld, rateTxFld, termTxFld, monthlyPayment;
	private TextArea payAmortTA;
	
	String currentInt;
	
	public MorgageCalculator()
	{
		String[] comboItems={"5.35","5.50","5.75"};
		//currentInt = comboItems [0];
		//remove later IntRates = new JComboBox(comboItems);
		
		//creates labels
		prinlb = new JLabel("Principal Amount:");
		rateLb = new JLabel("Interest Rate:");
		termLb = new JLabel("Term:");
		paymtLb = new JLabel("Monthly Payment:");
		
		//creates textfields
		prinTxFld = new JTextField("",10);
		rateTxFld = new JTextField("",5);
		rateTxFld.setEditable(false);
		termTxFld = new JTextField("",5);
		monthlyPayment = new JTextField("",10);
		monthlyPayment.setEditable(false);
		
		//combobox pulldown
		IntRates = new JComboBox(comboItems);
		IntRates.setEditable(false);
		/*ComboBox doesn't need it
		 IntRates.addActionListener(this);*/
		payAmortTA = new TextArea(20,50);
		
		//create buttons
		calBtn = new JButton("Calculate");
		calBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				calculateMortgage();
			}
		});
		
		resetBtn = new JButton("Reset");
		resetBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				prinTxFld.setText("");
				rateTxFld.setText("");
				termTxFld.setText("");
				monthlyPayment.setText("");
				payAmortTA.setText ("");
			}
		});
		
		//add labels and fields
		add(prinlb);
		add(prinTxFld);
		add(rateLb);
		add(IntRates);
		add(rateTxFld);
		add(termLb);
		add(termTxFld);
		add(paymtLb);
		add(monthlyPayment);
		add(payAmortTA);
		add(calBtn);
		add(resetBtn);
	}
	
	public void calculateMortgage()
	{
	
		//string array to accept which terms to use
		rateTxFld.setText(IntRates.getSelectedItem().toString());
		double principle=Double.parseDouble (prinTxFld.getText());
		double dblrateTxFld=Double.parseDouble(rateTxFld.getText());
		
		if (dblrateTxFld == 5.35)
		termTxFld.setText("7");
		
		else if (dblrateTxFld == 5.50)
		termTxFld.setText("15");
		
		else if (dblrateTxFld == 5.75)
		termTxFld.setText("30");
		
		int inttermTxFld=Integer.parseInt(termTxFld.getText());
		
		// Formats the output of dollar figures
		DecimalFormat two_decimal=new DecimalFormat("$0,000.00");
		
		double Payment;
		double InterestPaid;
		double prinTxFldBal;
		double temp;
		int Months;
		double intMonthlyRate = dblrateTxFld/100;
		int MonthTerm = inttermTxFld * 12;
		Months=MonthTerm;
		
		//formulas
		Payment=(principle * (intMonthlyRate/12)) / …
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

That is the main purpose behind action listener that on mouse click you want to get something done

JButton btn = new JButton();
btn.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent ae){
        //call which ever method or numerous methods to do something
        //retrieve data from form fields and send it for validation
       //get data from database and fill form fields
    }
}
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Data retrieved from database with use of servlet (not like your attempt above), returned back or passed to next page where with use of JSTL you would be able to do it much simpler.
You can pick up some general hints and tips from this tutorial

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You exposing your users/visitors to security risk. Why would I want to send my mobile number attached to easy readable http request?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Use JFrame to build what ever you need

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Deleting file JSP code

<%
File f=new File("c:\\imagesFolder\\pig.jpg");

f.delete();

%>

In linux machine you have to use different separator

Search platform Independent separator for operating system

I'm trying to show dreamer14 how to do things the correct way and you just drop in some scriplet solution? Also you made few other post where you even suggested to do DB connectivity from JSP, I do not think they will be overly popular.
Not that I did not use scriplets before too, but since then I made some progress in this field

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

That explain a lot. If you use command line to compile it you need to do it as follows

javac com/stonehambey/ecommerce/Storefront.java

where both files have to be in respectable locations and you need to run javac from the directory that is parent to your "com" so in your case judging by pasted console output in java directory

dan@dan-laptop:~/java$ javac /com/stonehambey/ecommerce/Storefront.java
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I see nothing wrong with it. Do you mind to post Storefront.java?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Ohh, little slower today.
In your class Item, did you declare constructor that will initialize this class variable with 4 provided values? Something like this?

public Item(int id, String name, double price, int quant){
    itemID = id;
    itemName = name;
    itemPrice = price;
    itemQuant = quant;
}
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Not the location of the file, but does the class Item starts with

package com.stonehambey.ecommerce

???

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You need to close BufferedReader and FileReader before you attempt to do something with that file. One of many rules, close anything opened as soon you not need it!

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Do you have "package" declaration of your Item class?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Do you want to share the code, or it is not possible as you do not want get accused of plagiarism by your teacher and therefore we need to work it out blind folded?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

This works fine.

import java.io.File;
import java.io.IOException;

/**
 * Delete a file from within Java
 * 
 * @author Ian F. Darwin, http://www.darwinsys.com/
 * @version $Id: Delete.java,v 1.5 2004/02/09 03:33:47 ian Exp $
 */
public class Delete {
  public static void main(String[] argv) throws IOException {

    // Construct a File object for the backup created by editing
    // this source file. The file probably already exists.
    // My editor creates backups by putting ~ at the end of the name.
    File bkup = new File("C:\\test.txt");
    // Quick, now, delete it immediately:
    bkup.delete();
  }
}

Is there anything else you do with the file before deleting? Like using for temporary writing?

PhiberOptik commented: Lots of help thanks! +1
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

OK then ( Just small warning, what you did by creating another post in different sections is something we do not like to see - please refer to forum rules 5th paragraph of Keep It Organized in regards of forum flooding. So in the future if this happens please click on the "Flag Bad Post" and type short message like "Please move it to JavaScript section")
If you can please close this post/mark as solved so as other do not get "cute" ideas

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Are you sure that you asking your question in correct forum section? You talking about JavaScript in Java forum section. Just in case you do not know Java is not same as JavaScript

PS: You will need to elaborate your question it does not really make too much sense.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Test class as suggested

public class Test
{
	private String question;
	private String optionA;
	private String optionB;
	private String optionC;
	private String answer;
	
	public Test(){}
	
	public Test(String quest, String oA, String oB, String oC, String ans)
	{
		setQuestion(quest);
		setOptionA(oA);
		setOptionB(oB);
		setOptionC(oC);
		setAnswer(ans);
	}
	
	private void setQuestion(String str){ question = str;}
	public String getQuestion(){ return question;}
	
	private void setOptionA(String str){ optionA = str;}
	public String getOptionA(){ return optionA;}
	
	private void setOptionB(String str){ optionB = str;}
	public String getOptionB(){ return optionB;}
	
	private void setOptionC(String str){ optionC = str;}
	public String getOptionC(){ return optionC;}
	
	private void setAnswer(String str){ answer = str;}
	public String getAnswer(){ return answer;}
}

Your re-done code, I made change to name( class name starts with capital letter any every other word in the name should start with capital too hence new class name SwingQuestionnaire) and also renamed some variables as to make it easier to work with it. Original names jcomp1 - jcomp6 are meaningless and difficult to remember which one is what

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

public class SwingQuestionnaire extends JPanel implements ActionListener{
    private JLabel titleLabel;
    private JLabel questionNumLabel;
    private JButton nextButton;
    private JLabel questionLabel;
    private JRadioButton jrbA;
    private JRadioButton jrbB;
    private JRadioButton jrbC;
    private int score;
    private int qNum = 0;
    private Test[] test = new Test[3];


    public SwingQuestionnaire() {
        //construct components
        JSeparator line1 = new JSeparator (JSeparator.HORIZONTAL);
        ButtonGroup group = new ButtonGroup();
        //int score;
        initializeTest();
        titleLabel = new JLabel ();
        questionNumLabel = new JLabel();
        
        questionLabel = new JLabel ();
        jrbA …
Ezzaral commented: Nice example. +16
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

The questions and the answers will be hard coded or read from file or database?