Java Q's

Status
Not open for further replies.

patonb

Golden Master
Messages
9,748
Location
In Gov't Regulated Cubical
K, so my java self teaching is going okay, but I've run into a problem.I'm creating popup windows, and I get the window to popup, but its blank. A simple message should be shown but nope.
Added menu bars.. they show up but yet the message doesn't.
ALL LEGAL java and word for word from text, btw.

Is IE blocking my java popup from working??

thanks
 
K here it is:

Popupindow.java:

import java.awt.*;

public class Popupindow extends java.applet.Applet{
Frame window;

public void init(){
add(new Button("Open"));
add(new Button("Close"));

window = new BaseFrame("A Popup Window");
window.resize(150,150);
window.show();
}

public boolean action(Event evt, Object arg){
if(evt.target instanceof Button){
String label=(String)arg;
if (label.equals("Open")){
if (!window.isShowing())
window.show();
}

else if (label.equals("Close")){
if(window.isShowing())
window.hide();
}
return true;
}
else return false;
}
}

BaseFrame.java:

import java.awt.*;

class BaseFrame extends Frame{
String message = "This is a window";

BaseFrame(String title){
super(title);
setFont (new Font("Helvetica", Font.BOLD, 30));
}

public boolean handleEvent(Event evt){
if(evt.id == Event.WINDOW_DESTROY) hide();
return super.handleEvent(evt);
}

public void paint(Graphics g){
g.drawString(message, 20,20);
}
}

result:
 

Attachments

  • result.jpg
    58 KB · Views: 24
Sorry, I don't make GUI's with Java. I also think the best approach is to make console programs until you have learned the basics, regardless of which language you're learning. That's just my opinion, but I know many instructors/authors share that point of view.
 
I'm actually half way through the book...... It's just so odd. Its like my simple drawstring doesn't work/ is being stopped by IE.

Adding more to the basic window works, menu bars andd such, but linking them to events doesn't run.. The destroy_window does though.
 
I don't make GUI in Java either, but I seem to remember something about having to cast your Graphics class into a "Graphics2D" class with an explicit cast before using it, but I think thats only for certain things, and in the most recent levels of Java.
 
Status
Not open for further replies.
Back
Top Bottom