Tạo 1 menu bar đơn giản .
Tại sao nó cứ báo lỗi không load được hàm main?? ai giúp mình với
Mã:
package baiawt1;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuDemo extends JFrame implements ActionListener{
public MenuDemo(){
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
java.awt.Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JMenu colorMenu = new JMenu("Colors");
JMenuItem item;
item = new JMenuItem("Red");
item.addActionListener((ActionListener) this);
colorMenu.add(item);
item = new JMenuItem("Orange");
item.addActionListener(this);
colorMenu.add(item);
item = new JMenuItem("Green");
item.addActionListener(this);
colorMenu.add(item);
JMenuBar menus = new JMenuBar();
menus.add(colorMenu);
setJMenuBar(menus);
}
public void actionPerformed(ActionEvent e) {
java.awt.Container contentPane = getContentPane();
if (e.getActionCommand().equals("Red")){
contentPane.setBackground(Color.red);
}
else
if (e.getActionCommand().equals("Orange")){
contentPane.setBackground(Color.orange);
}
else
if (e.getActionCommand().equals("Green")){
contentPane.setBackground(Color.green);
}
}
public static void main(String[] args) {
MenuDemo menuGui = new MenuDemo();
menuGui.setVisible(true);
}
}
View more random threads:
Ngọc Bích xanh bản chất thuộc dòng đá đá hoa (jade). Và cẩm thạch là tên gọi chung của ngọc bích. Vì thực chất chúng thuộc dòng đá đa khoáng được hình thành từ chất Silicat dưới dạng dioxy. Ngọc bích...
Chia sẻ Vòng tay ngọc bích xanh là...