[Java] Lägga till menu-problem
Jag har lite problem med att få min menu att visa sig i lvcMainWindow, och jag kommer inte på nåt sätt att lägga till den så att den inte genererar massa fel...
Här kommer filerna i alla fall:
//lvc.java
/** lvc - LedningsVakt Central
*
* Version: 0.0.1alpha1
*
*/
/**
* lvc - The name of the game
*/
class lvc {
/**
* Main Class
*/
public static void main(String[] args) {
/**
* call the main window
*/
new lvcMainWindow();
}
}
//lvcMainWindow.java
/* Import AWT & SWING for graphics components */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
//public class lvcMainWindow extends JFrame implements ActionListener {
public class lvcMainWindow extends JFrame {
/** lvcMainWindow Constructor */
public lvcMainWindow() {
/** Construct a JDesktopPane named: lvcMW */
JDesktopPane lvcMW = new JDesktopPane();
/* lvcMW Title: LedningsVakt Central */
setTitle("LedningsVakt Central");
/* lvcMW Bounderies and Size */
setBounds(15, 15, 600, 440);
/* Make lvcMW Visible */
setVisible(true);
/* not sure what this does */
setContentPane(lvcMW);
/* Make a nice colored background */
lvcMW.setBackground(new Color(50, 50, 50));
/* Add operation for exit */
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent eaEvent) {
exitApp(eaEvent);
}
});
/** Add the menubar */
//lvcMenuBar();
}
/** lvcMenuBar Constructor */
public void lvcMenuBar() {
/** Call for the menubar */
new lvcMenuBar();
}
/** Exit the Application */
private void exitApp(WindowEvent eaEvent) {
System.exit(0);
}
}
//lvcMenuBar.java
/* Import AWT & SWING for graphics components */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class lvcMenuBar {
public lvcMenuBar() {
JMenuBar lvcMB = new JMenuBar();
JMenu lvcMenuFile = new JMenu();
JMenuItem mbFileExit = new JMenuItem();
lvcMenuFile.setText("Arkiv");
mbFileExit.setText("Avsluta");
mbFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent mbEvent) {
mbFileExit(mbEvent);
}
});
lvcMenuFile.add(mbFileExit);
lvcMB.add(lvcMenuFile);
}
private void mbFileExit(ActionEvent mbEvent) {
/**
* When Arkiv(File)/Avsluta(Exit) is pressed, exit application.
*/
System.exit(0); // Add your handling code here:
}
}
Jag har säkert missat nåt basic bara...
Som hur jag får lvcMenuBar att lägga sig i min JDesktopPane i lvcMainWindow...
De flesta saker jag testat ger mig unresolved symbols, eller declaration type missing.
Den koden som är ovan, kompilerar utan errors, körs ok, men uten menuBaren...
¤Hakuna Matata¤
# Ibland försvinner 'j', 'å', 'ä' och 'ö'...
Signatur redigerad av GAPa. I textstorlek tre får man bara ha en rad.