I have the next problem: I'm calling a class from my Main, that have to show a JFrame. I can't even continue with my program because when I try to run it, the JFrame doesn't show. I'm using Eclipse.
Main:
package System;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.awt.Menu;
import java.awt.*;
import javax.*;
import javax.swing.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
new Menu();
}
}
Second class:
package System;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.awt.*;
import javax.*;
import javax.swing.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Menu {
private JFrame ventana = new JFrame("Sistema de Productos Químicos");
private JButton sup = new JButton("Supervisor");
private JButton oper = new JButton("Operario");
Menu()
{
ventana.setSize(500,500);
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.add(sup);
ventana.add(oper);
ventana.setVisible(true);
}
}
Thanks!
because your jframe class name is Menu
and you have import
import java.awt.Menu;
this create a new awt menu
instead of your Menu class which create a jframe
new Menu();
to fix this change the name of the Menu class to something different.
for instance
public class MyMenu { //
如果你玩弄 System.out.println("Say something random"),这是当你的程序不工作并且不是语法错误时要做的事情,你会发现 Main 类甚至没有调用 Menu 类,以便“减少”您的搜索区域,我还没有发现问题,当我发现时会更新答案。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.