Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2004, 03:52 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to starsailor
Default can an applet read from a file

ive been trying to do this code and cant get it to read can anybody plaese help

import java.awt.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;




public class Assessement2 extends JApplet implements ActionListener{


    JLabel Title,Photo,Author,Topic,LQuote;
    JComboBox TopicCombo,AuthorCombo;
    JButton QuoteButton;
    JTextArea QuoteArea;//various variables that i needed to complete the program




    ArrayList theauthor = new ArrayList();
    ArrayList thesubject = new ArrayList();
    ArrayList Quote = new ArrayList();


public void init(){//this method is used to organise the interface


        Container c =getContentPane();
        c.setLayout(null);


        Title=new JLabel("Quote Generator", JLabel.CENTER);
        Title.setFont(new Font("Serif", Font.BOLD, 24));
        Title.setForeground(Color.white);
        Title.setBounds(0,5,350,30);
        c.add(Title);

        //Photo=new JLabel(candle.gif);

        //private Image candle;

        Author=new JLabel("Authors Name");
        Author.setForeground(Color.white);
        Author.setBounds(10,40,150,20);
        c.add(Author);
        //FileLoad();

        AuthorCombo=new JComboBox();
        AuthorCombo.setBounds(10,60,150,25);
        c.add(AuthorCombo);

        Topic=new JLabel("Topic Area");
        Topic.setForeground(Color.white);
        Topic.setBounds(190,40,150,25);
        c.add(Topic);

        TopicCombo=new JComboBox();
        TopicCombo.setBounds(190,60,150,25);
        c.add(TopicCombo);

        LQuote=new JLabel("Quote", JLabel.CENTER);
        LQuote.setForeground(Color.white);
        LQuote.setBounds(0,100,350,25);
        c.add(LQuote);

        QuoteArea=new JTextArea();
        QuoteArea.setBounds(30,130,290,130);
        c.add(QuoteArea);

        QuoteButton=new JButton("Press Here to Enter the Quote into the System");
        QuoteButton.setBounds(2,270,348,30);
        QuoteButton.setForeground(Color.white);
        c.add(QuoteButton);
        QuoteButton.addActionListener(this);
        setBackground ( Color.black );
}





 public void FileLoad() {


    try {
      // Open the file that stores my quotes
        FileReader quoteStream = new FileReader ("Data.txt");
        BufferedReader quoteIn = new BufferedReader (quoteStream);

      String str, tmp;
      boolean FQuote = false;
      while ((str = quoteIn.readLine()) != null) {
        Quote.add(str);
      }

      // Close the File
        quoteIn.close();
    } catch (IOException except) {
      JOptionPane.showMessageDialog (null, "The File was not readable");
    }
  }

  public void Randomise() {
    int QuoteButton = (int)(Math.floor(Math.random()*(Quote.size()-1)+1));
    DisplayQuote(QuoteButton);
  }

  public void DisplayQuote(int quoteIndex) {
    TopicCombo.setSelectedIndex(quoteIndex+1);
    AuthorCombo.setSelectedIndex(quoteIndex+1);
    QuoteArea.setText ("");
    String s=(String)theauthor.get(quoteIndex);
    String st[]=s.split("#");
    QuoteArea.append(st[2]);
  }

  private Object MakeObject(final String item) {


    return new Object() { public String toString() { return item; } };
  }



  public void actionPerformed (ActionEvent e) {


    if (e.getSource() == QuoteButton) {
      Randomise();
    } else if (e.getSource() == AuthorCombo) {
      DisplayQuote(AuthorCombo.getSelectedIndex()-1);
    } else if (e.getSource() == TopicCombo) {
      DisplayQuote(TopicCombo.getSelectedIndex()-1);
    }
  }

}

 
Old January 7th, 2005, 12:58 PM
Registered User
 
Join Date: Mar 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does the applet have privileges to access the file system?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
setting codebase for applet inside jsp file picky Java Basics 0 December 12th, 2006 08:12 AM
Applet file access kp_kurian Java GUI 0 June 13th, 2004 10:20 PM
Java Applet that can read XML DOM and display text sankar XML 3 February 16th, 2004 11:16 AM
Java Applet that can read an XML file sankar J2EE 1 December 25th, 2003 05:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.