F
FrankTheFox
Gast
Hallo
ich habe folgendes Problem und keine Lösung:
Meine Fehlermeldung:
cannot find symbol
symbol : constructor ClsActionListener(java.lang.String,javax.swing.JFrame,java
x.swing.JMenuItem)
location: class ArtistAA.ClsActionListener
item4.addActionListener(new ClsActionListener ("metal" , Frame, item4));
^
1 error
Gruß
ich habe folgendes Problem und keine Lösung:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.*;
import java.net.*;
public class ArtistAA extends JFrame{
private static JFrame MDIFrame;
static String metalClassName =
"javax.swing.plaf.metal.MetalLookAndFeel";
static String motifClassName =
"com.sun.java.swing.plaf.motif.MotifLookAndFeel";
static String winClassName =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static JMenuBar createAndShowMenu(JFrame Frame) {
JMenuBar mnuBar = new JMenuBar();
JMenu fMnu = new JMenu("File");
fMnu.setMnemonic('F');
fMnu.setToolTipText("Main file menu...");
JMenuItem item1= new JMenuItem("Open");
item1.addActionListener(new ClsActionListener ("Open" , Frame));
fMnu.add(item1);
JMenuItem item3= new JMenuItem("Exit");
item3.addActionListener(new ClsActionListener ("Exit" , Frame));
fMnu.add(item3);
mnuBar.add(fMnu);
JMenu eMnu = new JMenu("Edit");
eMnu.setMnemonic('E');
eMnu.setToolTipText("Main edit menu...");
JMenuItem item2= new JMenuItem("Edite File");
item2.setEnabled(false);
item2.addActionListener(new ClsActionListener ("Edit" , Frame));
eMnu.add(item2);
mnuBar.add(eMnu);
JMenu LFMnu = new JMenu("Look & Feel");
LFMnu.setMnemonic('L');
LFMnu.setToolTipText("Select your desired look & feel...");
JMenuItem item4= new JCheckBoxMenuItem("metal");
item4.addActionListener(new ClsActionListener ("metal" , Frame, item4));
JMenuItem item5= new JCheckBoxMenuItem("motif");
item5.addActionListener(new ClsActionListener ("motif" , Frame, null));
JMenuItem item6= new JCheckBoxMenuItem("windows");
item6.addActionListener(new ClsActionListener ("windows" , Frame, null));
LFMnu.add(item4);
LFMnu.add(item5);
LFMnu.add(item6);
mnuBar.add(LFMnu);
return mnuBar;
}
private static JFrame createAndShowMDI() {
// ------------Create an internal frame: MDI Child window!!!!!
boolean resizable = true;
boolean closeable = true;
boolean maximizable = true;
boolean iconifiable = true;
JInternalFrame iframe = new JInternalFrame("Gutachter zuordnen",
true,
true,
true,
true);
// Set an initial size
int width = 200;
int height = 200;
iframe.setSize(width, height);
// By default, internal frames are not visible; make it visible
iframe.setVisible(true);
// Add components to internal frame...
iframe.getContentPane().add(new JTextArea());
//--------------------------------------------------------------------------
// Add internal frame to desktop : Now MDIChild is added to desktop pane!!!!
JDesktopPane desktop = new JDesktopPane();
desktop.add(iframe);
// Display the desktop in a top-level frame
JFrame frame = new JFrame("Artist");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setIconImage(new ImageIcon("Artist.jpg").getImage());
//Add internal frame to MDI Frame !!!!!
frame.getContentPane().add(desktop, BorderLayout.CENTER);
frame.setSize(1000, 800);
return frame;
}
public static void main(String args[]) {
String idb ="is20.idb.cs.tu-bs.de/";
String idb_short ="is.idb.cs.tu-bs.de/";
if(idb_short.equals(idb.substring(0,2)+idb.substring(4,idb.length()))){
System.out.println("Artist (Ausschnittsweise realisiertes Tagungsinformationssystem - Toll!)");
System.out.println("-----------------------------------------------------------------------");
System.out.println("You propably connect from another node using e.g. 'ssh'");
try {
String s;
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
do {
System.out.print("Are you sure to start Artist (Y\\N)?");
s = in.readLine();
if (!s.equals("Y") || !s.equals("N")){
System.out.println("Please enter 'Y' or 'N' !");};
if (s.equals("N") || s.equals("n")){
System.out.print("Terminate Artist!");
System.exit(0);};
}while(!s.equals("Y"));
}
catch(IOException e){
}
}
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch(UnknownHostException e){
System.out.println("No local Address!!!");
}
// System.exit(0);
MDIFrame = createAndShowMDI();
JMenuBar mnuBar =createAndShowMenu(MDIFrame);
MDIFrame.setJMenuBar(mnuBar);
MDIFrame.addKeyListener( new ClsKeyListener());
MDIFrame.addWindowListener( new ClsWindowListener());
MDIFrame.setVisible(true);
}
public static class ClsKeyListener extends KeyAdapter
{
public void keyPressed( KeyEvent k )
{
System.out.println("Keypressed!!");
if( k.getKeyCode()==10)
System.out.println( k.getSource().toString() );
}
public void keyReleased(KeyEvent k){}
public void keyTyped(KeyEvent k){}
}
public static class ClsWindowListener extends WindowAdapter
{
public void windowClosing( WindowEvent e )
{
/*event.getWindow().dispose();*/
System.out.println("Ok, Naacht.........");
}
public void windowIconified( WindowEvent e )
{
/*event.getWindow().dispose();*/
System.out.println("Ok, bin ein Icooooon.........");
}
public void windowActivated( WindowEvent e )
{
/*event.getWindow().dispose();*/
/*System.out.println("Ok, Hellooooo........."); */
}
public void windowClosed( WindowEvent e )
{
// Das Fenster ist geschlossen, und jetzt können wir hier
// weitermachen, etwa mit System.exit(), wenn alles
// vorbei sein soll.
}
}
public static class OpenFileAction extends AbstractAction
{
JFileChooser fc;
JFrame Wnd;
public OpenFileAction(JFrame Frame, JFileChooser JFC){
this.fc = JFC;
this.Wnd = Frame;
}
public void actionPerformed(ActionEvent e){
System.out.println("OpenFile");
}
}
public static class SaveFileAction extends AbstractAction
{
JFileChooser fc;
JFrame Wnd;
public void actionPerformed(ActionEvent e){
System.out.println("OpenFile");
}
}
public static class ClsActionListener implements ActionListener
{
private final String ident;
private final JFrame Frame;
private final JCheckBoxMenuItem CBitem;
public ClsActionListener(String ident, JFrame Frame, JCheckBoxMenuItem CBitem){
this.ident=ident;
this.Frame=Frame;
this.CBitem=CBitem;
}
public ClsActionListener(String ident, JFrame Frame){
this.ident=ident;
this.Frame=Frame;
}
public void actionPerformed(ActionEvent event)
{
String cmd = event.getActionCommand();
if(cmd.equals("Exit")){
if (JOptionPane.showConfirmDialog(null,
"Exit Artist?", "Artist",
JOptionPane.YES_NO_OPTION)
== JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null,
"Ok, Artist will be terminated.");
System.exit(1);
}
}
if(cmd.equals("Open")){
FileFilter filter = new ClsFileFilter();
JFileChooser fc = new JFileChooser();
fc.setFileFilter(filter);
Action openAction = new OpenFileAction(Frame,fc);
int result = fc.showOpenDialog(Frame);
if(result == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
fc.getSelectedFile().getName());
}
}
if(cmd.equals("metal")){
try{
UIManager.setLookAndFeel(metalClassName);
SwingUtilities.updateComponentTreeUI(Frame);
CBitem.setSelected(true);
//MDIFrame.pack();
}
catch(Exception e){
System.out.println("Could not load metal look & feel");
}
}
if(cmd.equals("motif")){
try{
UIManager.setLookAndFeel(motifClassName);
SwingUtilities.updateComponentTreeUI(Frame);
CBitem.setSelected(true);
//MDIFrame.pack();
}
catch(Exception e){
System.out.println("Could not load motif look & feel");
}
}
if(cmd.equals("windows")){
try{
UIManager.setLookAndFeel(winClassName );
SwingUtilities.updateComponentTreeUI(Frame);
CBitem.setSelected(true);
//MDIFrame.pack();
}
catch(Exception e){
System.out.println("Could not load windows look & feel");
}
}
//System.out.println(cmd +" "+ ident);
}
}
}
Meine Fehlermeldung:
cannot find symbol
symbol : constructor ClsActionListener(java.lang.String,javax.swing.JFrame,java
x.swing.JMenuItem)
location: class ArtistAA.ClsActionListener
item4.addActionListener(new ClsActionListener ("metal" , Frame, item4));
^
1 error
Gruß