|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] RE: a few java questions
try this:
javac uitest.java -Xstdout > error.txt
it works. I guess javac defaults to outputting to stderr (which just
happens to be the console) instead of stdout, and stderr doesn't get
redirected for some reason.
and for the rest of the code... you are using the old event model for one
thing (i tried not to change too much of that.. had to delete some things)
and also i couldn't get it to work using applet. seeing as you obviously
want an application... i just used Frame. I'll leave it to you to figure
out which bits have changed.
//
Imports --------------------------------------------------------------------
-
import java.awt.*; // For AWT GUI.
import java.awt.event.*; // For AWT event-handling.
import javax.swing.JOptionPane; // For message boxes (if any).
/*this is just a sample program to test out some UI components*/
public class uitest extends Frame implements ActionListener {
public uitest () {
Panel p = new Panel();
p.setLayout(new FlowLayout(FlowLayout.LEFT));
/*I want two buttons. One that says "submit form" and another
that says "cancel" */
Button submit = new Button("Submit Form");
Button cancel = new Button("Reset Form");
/* I want 5 text fields: name, address, phone number, age,
and password */
TextField name = new TextField("type your name", 27);
TextField address = new TextField("your address here", 30);
TextField phone = new TextField(15);
TextField age = new TextField(3);
TextField password = new TextField(8);
TextField city1 = new TextField(10);
//set an echocharacter for the password
password.setEchoCharacter('*');
/* I need one label for the top to say what the info is for
I need a few more right next to the text fields to say
what they are for */
Label top2 = new Label("Enter account information");
Label name2 = new Label("Name:", Label.LEFT);
Label address2 = new Label("Address:");
Label phone2 = new Label("Phone #:");
Label age2 = new Label("Age:");
Label password2 = new Label("Password:");
Label blank2 = new Label(" ");
Label blank3 = new Label(" ");
Label blank4 = new Label(" ");
Label blank = new Label(" ");
Label blank6 = new Label(" ");
Label blank5 = new Label(" ");
Label blank7 = new Label(" ");
Label interest = new Label("What are your interests?");
Label occupation = new Label("What is your occupation?");
Label city = new Label("city");
Label money = new Label("Income:");
CheckboxGroup income = new CheckboxGroup();
Checkbox a30 = new Checkbox("$20,000-$30,000",income,false);
Checkbox a40 = new Checkbox("$30,000-$40,000",income,false);
Checkbox a50 = new Checkbox("$40,000-$50,000",income,false);
Checkbox a60 = new Checkbox("$50,000-$60,000",income,false);
Checkbox a70 = new Checkbox("$60,000-$70,000",income,false);
Choice occ = new Choice();
occ.addItem("Teacher");
occ.addItem("Marketer");
occ.addItem("Salesman");
occ.addItem("Programmer");
occ.addItem("Store owner");
occ.addItem("Store worker");
Checkbox books = new Checkbox("books");
Checkbox movies = new Checkbox("movies");
Checkbox music = new Checkbox("music");
Checkbox compute = new Checkbox("computers");
Checkbox tech = new Checkbox("technology");
Checkbox family = new Checkbox("family fun");
Checkbox shop = new Checkbox("shopping");
/*Now it's time to put the labels, buttons, and textfields
together. The first thing I add is the labels, then the
text fields beside them */
p.add(top2);
p.add(blank4);
p.add(interest);
p.add(books);
p.add(movies);
p.add(music);
p.add(compute);
p.add(tech);
p.add(family);
p.add(shop);
p.add(occupation);
p.add(occ);
p.add(blank3);
p.add(money);
p.add(a30);
p.add(a40);
p.add(a50);
p.add(a60);
p.add(a70);
p.add(blank6);
p.add(blank5);
p.add(blank7);
p.add(name2);
p.add(name); //name
p.add(address2); //label....and so on
p.add(address);
p.add(phone2);
p.add(phone);
p.add(age2);
p.add(age);
p.add(password2);
p.add(password);
p.add(city);
p.add(city1);
/*now that I have p.added all the labels and text fields, I
now p.add the buttons at the end. Note one thing. I p.added
some p.add methods that included a label variable called blank
now, blank is a label that has numbers like 2,3,4,5 and so on
the numbers must be used because, as it seems to me, you can
only p.add one label per panel of the same name. The blank
labels are used to space the panel components*/
p.add(blank);
p.add(blank);
p.add(blank2);
p.add(submit);
p.add(cancel);
add(p);
addWindowListener(new WindowCloserAndExiter(this));
}
/**
* Handle ActionEvents, such as menu-items chosen by the user.
*/
public void actionPerformed(ActionEvent e)
{
String itemText = e.getActionCommand();
// Process all "Database", "View" and "Help" menu-items, but *not*
those
// for the table-related menus: Countries, Competitors, etc.
if (itemText.equals("..."))
{
// ...
}
else if (itemText.equals("..."))
{
// ...
}
else
JOptionPane.showMessageDialog(null,
"Unexpected action: '" + itemText
+ "'.",
"Error in '" +
getClass().getName() + ".actionPerformed'",
JOptionPane.ERROR_MESSAGE);
}
void handlebutton(String nm) {
}
public static void main(String arg[]){
Frame test = new uitest();
test.setSize(400, 150);
test.show();
}
}
////////////////////////////////////////////////////////////////////////////
//////
// WindowCloser.java. this is just a nice way to make sure your windows
close properly.
////////////////////////////////////////////////////////////////////////////
//////
//
Imports --------------------------------------------------------------------
-
import java.awt.*; // For AWT GUI.
import java.awt.event.*; // For AWT event-handling.
// WindowCloser class
==========================================================
/**
* A WindowCloser object is an event-handler that can be registered as
* a WindowListener, to allow the "close" button to close a window, without
* having to write any further code.
* This class is derived from WindowAdapter so we don't have to implement
all
* seven of the windowListener methods.
*/
public class WindowCloser extends WindowAdapter
{
/** Keep a reference to the window to which we're listening. */
private Window window;
/**
* Constructor. Parameter "newWindow" is the window object that wants
to
* be able to close. It may be a subtype of Window, i.e. a frame window
* or a dialog box.
*/
public WindowCloser(Window newWindow)
{
// Construct a new WindowMinder object by recording a reference to
// the window to which it belongs.
window = newWindow;
}
/**
* Handle a request by the user to close the window.
*/
public void windowClosing(WindowEvent e)
{
if (e.getSource() == window)
{
window.dispose();
}
}
}
////////////////////////////////////////////////////////////////////////////
//////
// WindowCloserAndExiter.java. this is just a nice way to make sure your
windows
// close properly and exit the application
////////////////////////////////////////////////////////////////////////////
//////
/**
* A WindowCloserAndExiter object is an event-handler that can be registered
as
* a WindowListener, to allow the "close" button to close a window and then
exit
* the entire program, without having to write any further code.
* Most of its functionality is inherited from the WindowCloser class. *
*/
public class WindowCloserAndExiter extends WindowCloser
{
/**
* Constructor. Parameter "newWindow" is the window object that wants
to
* be able to close. It may be a subtype of Window, i.e. a frame window
* or a dialog box.
*/
public WindowCloserAndExiter(Window newWindow)
{
super(newWindow);
}
/**
* Handle a request by the user to close the window and exit.
*/
public void windowClosing(WindowEvent e)
{
super.windowClosing(e);
System.exit(0);
}
}
//
that's it. hope this helps.
> -----Original Message-----
> From: gameprogrammer-owner@gameprogrammer.com
> [mailto:gameprogrammer-owner@gameprogrammer.com]On Behalf Of Bob
> Pendleton
> Sent: Thursday, April 06, 2000 8:28
> To: gameprogrammer@gameprogrammer.com
> Subject: Re: a few java questions
>
>
>
>
> Tim Elder wrote:
> >
> > First question: I'm going to assume that you're using the
> command line compiler. You can't really slow it down but what you
> can do is pipe the output into a file, and read the file. You can
> do this by:
> >
> > javac FileName.java > errorfile.txt
>
> I thought so too. But then I tested it and it didn't work.
>
> >
> > The next question, the UI thing... that's a heck of a lot of
> code... have a look at what the errorfile.txt (or whatever you
> want to call it) says, and let me know then.
> >
> > Tim
> >
> > ___________________________________________
> > Beer is the path to the dark side. Beer leads to Stella,
> > Stella leads to Speights. Speights, leads to suffering
> >
> > >>> "Jonathan Smith" <jon_1_5@hotmail.com> 5/04/00 15:35:01 >>>
> > How can I slow down my java compiler? Everytime I try to
> compile it comes up
> > real fast and goes down even faster without seeing the errors
> or anything.
> >
> > =================================================================
> > The GameProgrammer.Com mailing list is for the open discussion
> > of any topic related to the art, science, and business of
> > programming games. This list is especially tolerant of beginners.
> > We were all beginners once
> >
> > To SUBSCRIBE or UNSUBSCRIBE please visit:
> > http://gameprogrammer.com/mailinglist.html
> =================================================================
> The GameProgrammer.Com mailing list is for the open discussion
> of any topic related to the art, science, and business of
> programming games. This list is especially tolerant of beginners.
> We were all beginners once
>
> To SUBSCRIBE or UNSUBSCRIBE please visit:
> http://gameprogrammer.com/mailinglist.html
>
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|