如何在菜单栏中导入图像 [英] How to import an image in menu bar
问题描述
我创建了一个简单的菜单栏,我不知道如何在可用空间中导入图像。
我的代码如下:
import java.awt.event。*;
import java.awt。*;
import javax.swing。*;
import java.io.IOException;
公共类MyMenu扩展JFrame {
JMenuBar菜单栏;
JMenu文件,编辑,联系,退出;
JMenuItem退出,打开,搜索,删除,注册,信息;
public MyMenu(){
setLayout(new FlowLayout());
// ___________________________ FILE __________________________________
menubar = new JMenuBar();
setJMenuBar(menubar);
file = new JMenu(Αρχείο);
menubar.add(file);
open = new JMenuItem(Άνοιγμαπελατολογίου);
file.add(open);
event e1 = new event(); //编译器错误
open.addActionListener(e1);
// __________________________________编辑____________________________
edit = new JMenu(Ενέργειες);
menubar.add(编辑);
search = new JMenuItem(Αναζήτηση);
edit.add(搜索);
registration = new JMenuItem(Καταχώρηση);
edit.add(注册);
delete = new JMenuItem(Διαγραφή);
edit.add(删除);
// _________________________________联系__________________________
contact = new JMenu(Επικοινωνία);
menubar.add(联系方式);
informations = new JMenuItem(Πληροφορίες);
contact.add(信息);
// ___________________________________ QUIT_____________________________
quit = new JMenu(Έξοδος);
menubar.add(退出);
exit = new JMenuItem(Έξοδος);
quit.add(退出);
event e = new event(); //编译器错误
exit.addActionListener(e);
}
公共类MyEvent实现ActionListener {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
public void actionPerformed2(ActionEvent e1){
final SimpleTableDemo a = new SimpleTableDemo(); //编译错误
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
a.createAndShowGUI();
}
});
}
}
public static void main(String [] args)抛出IOException {
MyMenu gui = new MyMenu();
gui.getContentPane()。add(panel); //编译器错误
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(2400,1900);
gui.setVisible(true);
}
}
它与班级面板
?如何利用可用空间并使用图像?
请在此处发布可从Java Compilator无错误运行的代码(在 JMenuBar
必修教程
2)在容器中布置组件
3) 如何编写动作监听器
4)如何使用图标
5)最后for set Image
as JMenuBar BackGround
你必须阅读有关
2D图形
I've created a simple menu bar and I don't know how to import an image in the free space.
My code is below:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.IOException;
public class MyMenu extends JFrame {
JMenuBar menubar;
JMenu file, edit, contact, quit;
JMenuItem exit, open, search, delete, registration, informations;
public MyMenu() {
setLayout(new FlowLayout());
//___________________________ FILE __________________________________
menubar = new JMenuBar();
setJMenuBar(menubar);
file = new JMenu("Αρχείο");
menubar.add(file);
open = new JMenuItem("Άνοιγμα πελατολογίου");
file.add(open);
event e1 = new event(); // Compiler Error
open.addActionListener(e1);
//__________________________________ EDIT ____________________________
edit = new JMenu("Ενέργειες");
menubar.add(edit);
search = new JMenuItem("Αναζήτηση");
edit.add(search);
registration = new JMenuItem("Καταχώρηση");
edit.add(registration);
delete = new JMenuItem("Διαγραφή");
edit.add(delete);
//_________________________________ CONTACT __________________________
contact = new JMenu("Επικοινωνία");
menubar.add(contact);
informations = new JMenuItem("Πληροφορίες");
contact.add(informations);
//___________________________________QUIT_____________________________
quit = new JMenu("Έξοδος");
menubar.add(quit);
exit = new JMenuItem("Έξοδος");
quit.add(exit);
event e = new event(); // Compiler Error
exit.addActionListener(e);
}
public class MyEvent implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
public void actionPerformed2(ActionEvent e1) {
final SimpleTableDemo a = new SimpleTableDemo(); // Compiler Error
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
a.createAndShowGUI();
}
});
}
}
public static void main(String[] args) throws IOException {
MyMenu gui = new MyMenu();
gui.getContentPane().add(panel); // Compiler Error
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(2400, 1900);
gui.setVisible(true);
}
}
It is related to the class Panel
? How can I take advantage of the free space and use an image?
please post here Runnable code without Errors from Java Compilator (marked in you code with // Compiler Error
) before any of your request for AddingImage / ImportImage in JMenuBar
required tutorials
1) JMenu, JMenuBar, JMenuItems
2) Laying Out Components Within a Container
3) How to Write an Action Listener
5) and finally for set Image
as JMenuBar BackGround
you have to read something about
2D Graphics
6) examples on this forum, here or here
这篇关于如何在菜单栏中导入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!