Michael Hall

Greenhorn
+ Follow
since Dec 17, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Hall

Well, That did the Trick. It works fine. Thanks a lot.
I assume since you are a greenhorn that you are not THE Steve Gibson.
16 years ago
Chapter 18? ServiceServer?
In the Head First Java book the Chat Client I am talking about is in Chapter 15 (at least in my version) and consists of VerySimpleChatServer and SimpleChatClient. Anyway when I run the server in one command prompt window and the client in another window and type in text in the client and send it I get the following errors:

java.lang.NullPointerException
at VerySimpleChatServer$ClientHandler.run(VerySimpleChatServer.java:19)
at java.lang.Thread.run(Unknown Source)

Here is code:


Line 19 is - while((message=reader.readLine()) != null){

Help - No Clue.
16 years ago
In chapter 15 of Head First Java I want to try out the SimpleChatClient and VerySimpleChatServer programs but I only have one computer. Is there a way I can set up a situation that passes as a server and a terminal on my desktop computer so I can run those programs in chapter 15? - Thanks
16 years ago
I didn't even see the static there. Must have been getting tired. Thanks - compiles ok. I'll have another question soon about the chat client program in chapter 15.
16 years ago
In chapter 15 of HFJ the following code is the first part of the SimpleChatClient code.


I am getting 10 errors all of the following type -

non-static variable incoming can not be referenced from a static context

concerning several variables and methods. Any suggestions? Thanks
16 years ago
For others who have the same problem I found that the following settings allow questions and answers of up to 30 chars to display ok.

display=new(JTextArea(10,30));
.
.
.
frame.setSize(700,500);

Found by trial & error as I said I don't understand the relationship between the Frame setSize()command and the JTextArea(int,int) constructor yet.
16 years ago
Ok I set the font and set horizontal scrollbar policy to ALWAYS and fiddled around with the size of frame and display to come up with the following


which displays the text ok but I still don't understand the relationship between the frame size and JTextArea size that prevents it from displaying sometimes. Where can I get an education in this?
Thanks for your help - this is better than a University!
16 years ago
I am having a problem getting the QuizCardPlayer program in Chapter 14 of the Head First Java Book to display the question that is reading from a file written out by QuizCardBuilder. I know the question is being read in and loaded into the ArrayList but it is not getting to the JTextArea. I have removed non related code. The example code below isolates the problem.



I can't get the text to display in the JTextArea. In the book there was a
display.setText() command but I determined that it had nothing to do with that so I removed it and just tried the above. Still nothing. Could use some help - thanks....
16 years ago
Ok Pauline - I just read your post. Thanks - I'll move it over there.
16 years ago
It's not the setText - Even this displays nothing -

//JTextAreaTest

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

public class JTextAreaTest{
private JTextArea display;
private JFrame frame;

public void go(){
frame=new JFrame("JTextArea Test");
JPanel mainPanel=new JPanel();
Font bigFont=new Font("sanserif",Font.BOLD,24);
display=new JTextArea("THIS IS A TEST",10,50);//forget the setText()
JScrollPane qScroller=new JScrollPane(display);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
mainPanel.add(qScroller);
frame.getContentPane().add(BorderLayout.CENTER,mainPanel);
frame.setSize(400,500);
frame.setVisible(true);
}
public static void main(String[] args){
JTextAreaTest jtextareatest=new JTextAreaTest();
jtextareatest.go();
}
}

Why Not?
16 years ago
Forget the button - even this does not display anything -

//JTextAreaTest

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


public class JTextAreaTest{
private JTextArea display;
private JFrame frame;

public void go(){
frame=new JFrame("JTextArea Test");
JPanel mainPanel=new JPanel();
Font bigFont=new Font("sanserif",Font.BOLD,24);
display=new JTextArea(10,50);
display.setFont(bigFont);
display.setLineWrap(true);
display.setWrapStyleWord(true);
display.setEditable(true);
display.setText("This is a test");//why does not this show up?
JScrollPane qScroller=new JScrollPane(display);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
mainPanel.add(qScroller);
frame.getContentPane().add(BorderLayout.CENTER,mainPanel);
frame.setSize(400,500);
frame.setVisible(true);
}
public static void main(String[] args){
JTextAreaTest jtextareatest=new JTextAreaTest();
jtextareatest.go();
}
}

Why doesn't "This is a Test" show up in the JTextArea? This is the problem I am experiencing with the code in chapter 14 of Head First Java book. Need Help... Thanks
16 years ago
Trying to debug the problem in the prior post I removed a lot of code not related to the problem and tried the code below.

//JTextAreaTest
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;

public class JTextAreaTest{
private JTextArea display;
private JFrame frame;
private JButton nextButton;

public void go(){
frame=new JFrame("JTextArea Text");
JPanel mainPanel=new JPanel();
Font bigFont=new Font("sanserif",Font.BOLD,24);
display=new JTextArea(10,50);
display.setFont(bigFont);
display.setLineWrap(true);
display.setWrapStyleWord(true);
display.setEditable(false);
JScrollPane qScroller=new JScrollPane(display);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
nextButton=new JButton("Display Text");
mainPanel.add(qScroller);
mainPanel.add(nextButton);
nextButton.addActionListener(new NextButtonListener());
frame.getContentPane().add(BorderLayout.CENTER,mainPanel);
frame.setSize(400,500);
frame.setVisible(true);
}
public class NextButtonListener implements ActionListener{
public void actionPerformed(ActionEvent ev){
display.setText("This is a test");
display.setVisible(true);//I added this thinking it might help but no
}
}
public static void main(String[] args){
JTextAreaTest jtextareatest=new JTextAreaTest();
jtextareatest.go();
}
}

As I said in the prior post this displays nothing in the JTextArea. Can anyone tell me why not?
Thanks...
16 years ago
Regarding the Head First Java book I am trying to get the QuizCardPlayer program in chapter 14 to work. I was able to get the QuizCardBuilder to work by adding the following inner class and main -

public class QuizCard{
String stringQuestion;
String stringAnswer;
public QuizCard(String stringQuestion,String stringAnswer){
this.stringQuestion=stringQuestion;
this.stringAnswer=stringAnswer;
}
public String getQuestion(){
return this.stringQuestion;
}
public String getAnswer(){
return this.stringAnswer;
}
}
public static void main(String[] args){
QuizCardBuilder quizCardBuilder=new QuizCardBuilder();
quizCardBuilder.go();
}

As I said that works ok. However while adding the same with appropriate changes to main to the QuizCardPlayer program I can't get that program to display the question in the JTextArea even tho the information from the file created by QuizCardBuilder is getting loaded into the ArrayList in QuizCardPlayer. The command
display.setText(currentCard.getQuestion());

where display is JTextArea display; that has been added to a JScrollPane with a JScrollPane(display) does not do anything. No output on the JTextArea at all. Everything else seems to be working ok. Also looking up JTextArea in documentation I can't find a setText() method.? Do the authors have any feedback on this or anyone else? Thank You.
16 years ago
What did Pierre De Fermat say? - in English please - thanks
16 years ago
Shouldn't you have said a reference to alist is passed - not a pointer? Please explain as I might be confused - thanks
16 years ago