Hi, (first post)
i am trying to learn and understand java and have run into a problem.
i am trying to get a new 3rd button working "image"
the button image is shut open a new windows with a image in it i weill post the main class "ButtonX" aswel as the window frames "BaseFrame1" and "ImageFrame1"
if you can fix it please tell my how so i can learn from it.
(ButtonX)
**************************************************
import java.awt.Button;
import java.awt.Event;
import java.awt.Frame;
public class ButtonX extends java.applet.Applet {
Frame window;
Button open, image, close;
public void init() {
open = new Button("Open Window");
add(open);
image = new Button("image");
add(image);
close = new Button("Close Window");
add(close);
window = new BaseFrame1("A Pop Up Window");
window.resize(250,200);
window = new ImageFrame1("A image");
window.resize(350,300);
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button) {
String label = (String)arg;
if (label.equals("Open Window")) {
if (!window.isShowing())
window.show();
} else {
if (window.isShowing())
window.hide();
}
return true;
} else
return false;
if (evt.target instanceof Button) {
String label = (String)arg;
if (label.equals("image")) {
if (!window.isShowing())
window.show();
} else {
if (window.isShowing())
window.hide();
}
return true;
} else
return false;
}
}
************************************************** ******
BaseFrame1
************************************************** ******
import java.awt.*;
class BaseFrame1 extends Frame {
String message = "This is a Window";
Label l;
BaseFrame1(String title) {
super(title);
setLayout(new BorderLayout());
l = new Label(message, Label.CENTER);
l.setFont(new Font("Helvetica", Font.PLAIN, 12));
add("Center", l);
}
public Insets getInsets() {
return new Insets(20,0,25,0);
}
}
************************************************** ****************
ImageFrame1
************************************************** ****************
import java.awt.*;
import javax.swing.*;
public class ImageFrame1 extends JPanel{
Image image;
public ImageFrame1(){
super();
image = Toolkit.getDefaultToolkit().getImage("ncis.jpeg");
}
public void paintComponent(Graphics g){
g.drawImage(image,50,10,200,300, this);
}
public static void main(String arg[]){
JFrame frame = new JFrame("ShowImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(600,400);
ShowImage panel = new ShowImage();
frame.setContentPane(panel);
frame.setVisible(true);
}
}
************************************************** *****************