I'm hoping someone out there can help me.
i have to use a 2nd class to create a JMenuBar to attach to a JFrame
i get an error :49: incompatible types

found   : javax.swing.JFrame
required: java.lang.String
return  aTestFrame;

(i have also tried something else and got a static/non static error)

here's the code thanks for any help!

import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class Driver{
public static void main(String[] args) {
TheWindowObject aTestFrame = new TheWindowObject ("test");

    }
}
class TheWindowObject{      

TheWindowObject(String title){
CreateWindow () ;
        }
TheWindowObject(String title, int height, int width){
        }

JFrame CreateWindow (){

String  title ="test";
int height =200 ;
int width=400 ;
JFrame aTestFrame= null; 

aTestFrame =new JFrame("test");
        aTestFrame.setSize (width, height);
        aTestFrame.setVisible (true);
        aTestFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return  aTestFrame;
}}
class MenuFactory {
    String MenuFactory (String menuInput){

    JFrame aTestFrame= null; 
    JMenuBar generate= null;
    JMenu createMenu;
    JMenuItem createMenuItem;
    // File Menu, F - Mnemonic
    createMenu = new JMenu("File");
    createMenu.setMnemonic(KeyEvent.VK_F);
    generate.add(createMenu );

    // File->New, N - Mnemonic
   createMenuItem = new JMenuItem("New", KeyEvent.VK_N);
   createMenu.add(createMenuItem);
    aTestFrame.setJMenuBar (generate );

return  aTestFrame;
   }
 }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I'm hoping someone out there can help me.
i have to use a 2nd class to create a JMenuBar to attach to a JFrame
i get an error :49: incompatible types
found : javax.swing.JFrame
required: java.lang.String
return aTestFrame;

(i have also tried something else and got a static/non static error)

here's the code thanks for any help!


import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class Driver{
public static void main(String[] args) {
TheWindowObject aTestFrame = new TheWindowObject ("test");

}
}
class TheWindowObject{

TheWindowObject(String title){
CreateWindow () ;
}
TheWindowObject(String title, int height, int width){
}

JFrame CreateWindow (){

String title ="test";
int height =200 ;
int width=400 ;
JFrame aTestFrame= null;

aTestFrame =new JFrame("test");
aTestFrame.setSize (width, height);
aTestFrame.setVisible (true);
aTestFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return aTestFrame;
}}
class MenuFactory {
String MenuFactory (String menuInput){

JFrame aTestFrame= null;
JMenuBar generate= null;
JMenu createMenu;
JMenuItem createMenuItem;
// File Menu, F - Mnemonic
createMenu = new JMenu("File");
createMenu.setMnemonic(KeyEvent.VK_F);
generate.add(createMenu );

// File->New, N - Mnemonic
createMenuItem = new JMenuItem("New", KeyEvent.VK_N);
createMenu.add(createMenuItem);
aTestFrame.setJMenuBar (generate );

return aTestFrame;
}
}

First of all The constructor of the class doesn't return. Secondly in line no 48 you have declared the method as return type String and then you are returning a string. I have altered your code to do what you desired.

import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class Driver{
public static void main(String[] args) {
TheWindowObject aTestFrame = new TheWindowObject ("test");

}
}
class TheWindowObject{

TheWindowObject(String title){
CreateWindow () ;
}
TheWindowObject(String title, int height, int width){
}

JFrame CreateWindow (){

String title ="test";
int height =200 ;
int width=400 ;
JFrame aTestFrame= null;

aTestFrame =new JFrame("test");
aTestFrame.setSize (width, height);
aTestFrame.setVisible (true);
aTestFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aTestFrame.setJMenuBar (new MenuFactory().Menu());
return aTestFrame;
}}
class MenuFactory {

    
JMenuBar Menu(){

JFrame aTestFrame= null;
JMenuBar generate= new JMenuBar();
JMenu createMenu;
JMenuItem createMenuItem;
// File Menu, F - Mnemonic
createMenu = new JMenu("File");
createMenu.setMnemonic(KeyEvent.VK_F);


// File->New, N - Mnemonic
createMenuItem = new JMenuItem("New", KeyEvent.VK_N);
createMenu.add(createMenuItem);
generate.add(createMenu );
//aTestFrame.setJMenuBar (generate );
return generate;

}
}
Comments
great help-thanks1
This question has already been answered. Start a new discussion instead.