Re: No buttons and minimized at a upper-left corner
Jack wrote:
Hi,
package com.etc.gui;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.io.*;
import java.util.*;
import java.awt.event.*;
public class LPRFrame extends Frame {
public LPRFrame() {
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileLoad = new MenuItem();
// Menu menuLearn = new Menu();
// MenuItem menuLearnLearn = new MenuItem();
Menu menuImg = new Menu();
menuFile.setLabel("File");
menuFileLoad.setLabel("Load Image");
menuImg.setLabel("Image/Data");
menuFile.add(menuFileLoad);
menuBar.add(menuFile);
menuBar.add(menuImg);
setTitle("LPR");
setMenuBar(menuBar);
setSize (new Dimension (640, 480));
}
}
With main at somewhere else
I assume your problem is that the above code (plus some you omitted)
causes a window to be displayed at minimum size and with no content visible?
I don't use AWT (why dont you use Swing?) but the following "works"
under JDK 1.5 after I implemented a minimal main()
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class LPRFrame extends Frame {
public LPRFrame() {
Menu menuFile = new Menu("File");
MenuItem menuFileLoad = new MenuItem("Load Image");
menuFile.add(menuFileLoad);
Menu menuImg = new Menu("Image/Data");
MenuBar menuBar = new MenuBar();
menuBar.add(menuFile);
menuBar.add(menuImg);
setMenuBar(menuBar);
setTitle("LPR");
setSize(new Dimension(640, 480));
}
public static void main(String[] args) {
LPRFrame frame = new LPRFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
I also put the menu labels into the constructors to save a few lines of
source code.