two problems I need help

Need solution, thanks!

java:62: cannot find symbol

symbol : variable FileInputStream

location: class ishome

FileInputStream = new FileInputStream(test);

^

java:67: read(java.io.Reader,java.lang.Object) in javax.swing.text.JTextComponent cannot be applied to (java.io.File)

displayArea.read(test);

^

2 errors

import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

import java.awt.Graphics;

import java.awt.Image;

import java.io.*;

import javax.swing.text.*;

import javax.swing.*;

publicclass ishomeextends Applet{

Button newsButton;

Button projectsButton;

Button issuesButton;

Button learnButton;

Button gamesButton;

Button aboutButton;

Panel panel;

Button helpdeskButton;

Image topBar;

File test;

JTextArea displayArea;

publicvoid init(){

ishomeLayout customLayout =new ishomeLayout();

setFont(new Font("Helvetica", Font.PLAIN, 12));

setLayout(customLayout);

newsButton =new Button("News");

newsButton.addActionListener(new NewsActionListener());

add(newsButton);

projectsButton =new Button("Projects");

//projectsButton.addActionListener(new ProjectsActionListener());

add(projectsButton);

issuesButton =new Button("Issues");

//issuesButton.addActionListener(new issuesActionListener());

add(issuesButton);

learnButton =new Button("Learn");

//learnButton.addActionListener(new LearnActionListener());

add(learnButton);

gamesButton =new Button("Games");

//gamesButton.addActionListener(new GamesActionListener());

add(gamesButton);

aboutButton =new Button("About Us");

//aboutButton.addActionListener(new AboutActionListener());

add(aboutButton);

helpdeskButton =new Button("Help Desk");

//helpdeskButton.addActionListener(new HelpdeskActionListener());

add(helpdeskButton);

displayArea =new JTextArea();

add(displayArea);

topBar = getImage(getCodeBase(),"topBar.jpg");

test =new File("test.txt");

FileInputStream =new FileInputStream(test);

setSize(getPreferredSize());

}

class NewsActionListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent e){

displayArea.append(test);

}

}

publicvoid paint(Graphics g){

g.drawImage(topBar, 10, 5,this);

}

publicstaticvoid main(String args[]){

ishome applet =new ishome();

Frame window =new Frame("ishome");

window.addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent e){

System.exit(0);

}

});

applet.init();

window.add("Center", applet);

window.pack();

window.setVisible(true);

}

}

class ishomeLayoutimplements LayoutManager{

public ishomeLayout(){

}

publicvoid addLayoutComponent(String name, Component comp){

}

publicvoid removeLayoutComponent(Component comp){

}

public Dimension preferredLayoutSize(Container parent){

Dimension dim =new Dimension(0, 0);

Insets insets = parent.getInsets();

dim.width = 687 + insets.left + insets.right;

dim.height = 494 + insets.top + insets.bottom;

return dim;

}

public Dimension minimumLayoutSize(Container parent){

Dimension dim =new Dimension(0, 0);

return dim;

}

publicvoid layoutContainer(Container parent){

Insets insets = parent.getInsets();

Component c;

c = parent.getComponent(0);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+92,72,24);}

c = parent.getComponent(1);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+116,72,24);}

c = parent.getComponent(2);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+140,72,24);}

c = parent.getComponent(3);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+164,72,24);}

c = parent.getComponent(4);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+188,72,24);}

c = parent.getComponent(5);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+212,72,24);}

c = parent.getComponent(6);

if (c.isVisible()){c.setBounds(insets.left+96,insets.top+92,576,392);}

c = parent.getComponent(7);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+268,72,24);}

c = parent.getComponent(8);

if (c.isVisible()){c.setBounds(insets.left+8,insets.top+268,72,24);}

}

}

[8589 byte] By [JavaBean5a] at [2007-11-27 5:19:25]
# 1

> java:62: cannot find symbol

> symbol : variable FileInputStream

> location: class ishome

> FileInputStream = new FileInputStream(test);

On the line the compiler is talking about you have said, in effect, something = expressionAnd the compiler is saying that "something" is not a variable it knows about. Perhaps you meant there to be a variable whose value will be a reference to the newly created FileInputStream.

The second error you posted does not relate to the code you posted.

pbrockway2a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 2
displayArea is a JTextArea which does not have a read method that accepts a File as a parameter.
floundera at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 3
which method would you use for reading?
JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 4
> which method would you use for reading?JTextComponent's read() method - it takes two arguments: a Reader (the stream to read from) and an Object which describes the stream (it can be null).
pbrockway2a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 5

The first one is a simple error. Its like saying int = 10; where u should be saying int x = 10. u missed the variable name. u could say FileInputStream fis = new FileInputStream(test);

u cant use the append function to append files. u can append only strings. u could read the whole file,store it in a string and then append it.

-...icedT...-a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 6

what if I do this...except i keep getting an exception error which I am still new to. can anyone help me?

ithome.java:67: e is already defined in actionPerformed(java.awt.event.ActionEvent)

} catch (IOException e) {

^

1 error

import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

import javax.swing.*;

import java.net.URL;

import java.io.IOException;

public class ithome extends Applet {

Image topBar;

JButton newsButton;

JButton projectsButton;

JButton issuesButton;

JButton learnButton;

JButton funButton;

JButton aboutButton;

JButton helpdeskButton;

JEditorPane editorPane;

JScrollPane editorScrollPane;

java.net.URL itURL;

public void paint(Graphics g) {

g.drawImage(topBar, 0, 0, this);

}

public void init() {

ithomeLayout customLayout = new ithomeLayout();

setFont(new Font("Helvetica", Font.PLAIN, 12));

setLayout(customLayout);

newsButton = new JButton("News");

newsButton.addActionListener(new NewsActionListener());

add(newsButton);

projectsButton = new JButton("Projects");

add(projectsButton);

issuesButton = new JButton("Issues");

add(issuesButton);

learnButton = new JButton("Learn");

add(learnButton);

funButton = new JButton("Fun");

add(funButton);

aboutButton = new JButton("About");

add(aboutButton);

helpdeskButton = new JButton("Help Desk");

add(helpdeskButton);

editorPane = new JEditorPane();

editorPane.setEditable(false);

editorScrollPane = new JScrollPane(editorPane);

add(editorScrollPane);

itURL = ithome.class.getResource("test.html");

topBar = getImage(getCodeBase(), "topBar.jpg");

setSize(getPreferredSize());

}

class NewsActionListener implements ActionListener{

public void actionPerformed(ActionEvent e) {

if (itURL != null) {

try {

editorPane.setPage(itURL);

} catch (IOException e) {

System.err.println("Attempted to read a bad URL: " + itURL);

}

} else {

System.err.println("Couldn't find file: test.html");

}

}

}

public static void main(String args[]) {

ithome applet = new ithome();

Frame window = new Frame("ithome");

window.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

applet.init();

window.add("Center", applet);

window.pack();

window.setVisible(true);

}

}

class ithomeLayout implements LayoutManager {

public ithomeLayout() {

}

public void addLayoutComponent(String name, Component comp) {

}

public void removeLayoutComponent(Component comp) {

}

public Dimension preferredLayoutSize(Container parent) {

Dimension dim = new Dimension(0, 0);

Insets insets = parent.getInsets();

dim.width = 791 + insets.left + insets.right;

dim.height = 542 + insets.top + insets.bottom;

return dim;

}

public Dimension minimumLayoutSize(Container parent) {

Dimension dim = new Dimension(0, 0);

return dim;

}

public void layoutContainer(Container parent) {

Insets insets = parent.getInsets();

Component c;

c = parent.getComponent(0);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+148,92,24);}

c = parent.getComponent(1);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+172,92,24);}

c = parent.getComponent(2);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+196,92,24);}

c = parent.getComponent(3);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+220,92,24);}

c = parent.getComponent(4);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+244,92,24);}

c = parent.getComponent(5);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+268,92,24);}

c = parent.getComponent(6);

if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+292,92,24);}

c = parent.getComponent(7);

if (c.isVisible()) {c.setBounds(insets.left+128,insets.top+148,632,392);}

}

}

JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 7
Did you even bother to read the error message?It says you have declared two variables called e. You cannot do this.
floundera at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 8
Nevermind about the error, i was being stupid. But the problem I am having now is when i press the news button nothing is displayed the in the editorpane.
JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 9
You are using the same variable (e) for both the ActionEvent and the IOException in actionPerformed().
pbrockway2a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 10
why does the buttons only show up when I mouse over it?
JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 11
> when i press the news button nothing is displayed the in the editorpane. Check the value of itURL at the start of that method. If it null, then nothing will happen.
pbrockway2a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 12
what should I set it to?
JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 13
I'm sorry, i thought you were talking about the mousing over button issue. Everything seems to be working but the buttons don't show up unless i mouse over it. any ideas?
JavaBean5a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 14

> Everything seems to be working but the buttons don't show up unless i mouse over

> it.

You are overriding Container's paint() method.. Try calling super.paint(g) so that the children get painted.

http://java.sun.com/javase/6/docs/api/java/awt/Container.html#paint(java.awt.Graphics)

pbrockway2a at 2007-7-12 10:42:46 > top of Java-index,Java Essentials,New To Java...
# 15
i'm unfamiliar with super paint.
JavaBean5a at 2007-7-21 21:25:34 > top of Java-index,Java Essentials,New To Java...
# 16

That's super.paint(g) with a dot.

It calls the parent (in a class sense - not a visual sense) of your applet and tells it to paint itself. The point is that an applet IS-A container and, as a container, it knows how to paint itself properly (ie paint all its children like those buttons). But when you define your own paint() method in applet you lose this behaviour (you override it).

pbrockway2a at 2007-7-21 21:25:34 > top of Java-index,Java Essentials,New To Java...
# 17
thanks a lot.
JavaBean5a at 2007-7-21 21:25:34 > top of Java-index,Java Essentials,New To Java...