Greg Walker

Greenhorn
+ Follow
since Sep 07, 2006
Merit badge: grant badges
For More
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 Greg Walker

Well that's just one example. What if I want to activate an option pane from teh BackCode class. The way I ahve it set up is in GUIclass there is a method

example: public void subscribeFailed(String newsgroup) {
//display option pane that says subscription failed
}

But to call that I need an instance of GUIclass...
GUIclass object = new GUIclass();

...to call the method to display the option pane

object.subscribeFailed("sci.physics");

The instantiation creates a brand new container (JFrame) every time it's created. So usually to avoid having to keep creating objects we declare them globably so all the methods can use them, but when I do this I get a initiation error message at the terminal prompt and it keeps displaying it as if in an infinite loop.
17 years ago

Originally posted by Paul Clapham:
It's hard to understand what you mean by that. Normally the reason you'd want to access the method of an instance is because you want to get information from the instance or you want to affect its state. If you want to do that repeatedly, then keep a reference to the object.

[ September 19, 2006: Message edited by: Paul Clapham ]



What I mean is in my GUI class when a user presses the "GO!" button that calls a method located in the BackCode class. The BackCode class then, for example, opens a file and displays that info in a textArea located in GUI class. To access the GUI class I need to have an instance of it. Every time I declare an instance it creates a whole new containier and I wind up with 20 containers after 20 button presses.

When I try to declare a global variable in the BackCode class my GUI freaks out and crashes.
[ September 19, 2006: Message edited by: Greg Walker ]
17 years ago
1. How do you format buttons, fields, areas, etc... to been seen where you want them in the container?

2.When running a program with a GUI class and a backcode class of methods to manipulate data, how do you keep from having to constantly instantiate new instances of the classes while being able to access their methods?
17 years ago
When dumping stuff into a text area how do you set up the side scroll bar so you can move up and down the text area to view info?
17 years ago
Now what if I wanted to do a one-to-many mapping, such as a group name <K> mapped to group numbers <V>, in which the values will be stored in a List?
17 years ago
Something to do with the nntp protocol...
17 years ago
I figured out why it's stalling, it was the server "news.readfreenews.net".
I switched to a diff host server and my original code works, but now this code fails again at the same portion I already posted due to NNTP protocol command error. Now I have to figure out why the command failed (returned 503 instead of 215).
17 years ago
Yeah that's what I did. That portion I posted is where it stops.
17 years ago
My code is stalling at this point in my program...


String response215 = in.readLine();
if (!response215.startsWith("215")) {
System.err.println("Protocol Error");
System.exit(1); }

System.out.println("check");

It never makes it to the SOP "check". Any ideas?
17 years ago
It never even gets into the for loop, it stalls at the portion of code for some reason....
17 years ago
It has something to do with this portion of code...

String response215 = in.readLine();

if (!response215.startsWith("215")) {
System.err.println("Protocol Error");
System.exit(1); }
17 years ago
Okay I'm trying to read in newsgroups from the host newsserver listed in my instance data. The programs compiles but freezes at startup. Here's the code (I guess copy and paste it into an editor to view it easier)


import java.io.*;
import java.net.*;
import java.util.*;



public class NewsManager {
public static void main(String[] args) {
//instance constants


//instance variables
String fname = ".newsrc"; //name of file to read from
String host = "news.readfreenews.net";
String home;//user's home directory
String separator;//path separator
int nntpServicePortNumber = 119;

/*********************************************************************/

//get user home directory and file separator
home = System.getProperty("user.home");
File dir = new File(home);
separator = dir.pathSeparator;

//check if .newsrc file exists, if not create it
File newsrc = new File(dir, ".newsrc");
try {
newsrc.createNewFile(); }
catch (IOException ex) {
System.out.println("File IO error"); }

BufferedReader in = null;
PrintWriter out = null;
Socket nntpSocket = null;

try {
FileWriter fw = new FileWriter(newsrc, true);
BufferedWriter bw = new BufferedWriter(fw);

try {
nntpSocket = new Socket(host, nntpServicePortNumber);
out = new PrintWriter(nntpSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
nntpSocket.getInputStream())); }

catch (UnknownHostException e) {
System.err.println("Don't know about host " + host);
System.exit(1); }

catch (IOException e) {
System.err.println("Couldn't get I/O for the connection.");
System.exit(1); }

try {
String response200 = in.readLine();

if (!response200.startsWith("2")) {
System.err.println("Protocol Error");
System.exit(1); }

String response215 = in.readLine();

if (!response215.startsWith("215")) {
System.err.println("Protocol Error");
System.exit(1); }

for (; {
String line = in.readLine();
if (line.startsWith(".")) break;
StringTokenizer toks = new StringTokenizer(line);
String name = toks.nextToken();

int first = 0;
String firstAsString = toks.nextToken();
try {
first = Integer.parseInt(firstAsString); }

catch (NumberFormatException ex) {
System.err.println("Bad number format? " + firstAsString);
System.exit(1); }

int last = 0;
String lastAsString = toks.nextToken();
try {
last = Integer.parseInt(lastAsString); }

catch (NumberFormatException ex) {
System.err.println("Bad number format? " + lastAsString);
System.exit(1); }

NewsGroup n = new NewsGroup(name, first, last);

try {
bw.write(name + first + last); }
catch (IOException ex) {
System.out.println("File IO error"); }

System.out.println(n);
}//end for

out.close();
in.close();
nntpSocket.close();
bw.close();
}//end try

catch (IOException ex) {
System.err.println("IO failure.");
ex.printStackTrace(); }
}//end try

catch (IOException ex) {
System.out.println("File IO error"); }
}
}
17 years ago
Well I have to write a mapping of newsgroups and articles read onto the file (newsrc).
17 years ago
Ah, so how would you create an actual file?
17 years ago
Can anyone show me an easy example of storing items in a sorted map? (The java tutorial is kinda confusing)
17 years ago