Pergunta

I was wondering how this would interfere with the main class when called, I have found no suitable way to make a main class and call it in a final.

 import java.awt.*;
  import java.awt.event.*;
import java.util.*;
 import java.io.*;
 import javax.imageio.*;
  import javax.swing.*;


 class Converter extends JFrame  implements 
 KeyListener, ItemListener, MouseListener {


//insert body here//    


@Override
        public void paintComponents (Graphics g)  {g.drawImage(icon.getImage(), 0, 20, 500,210, this);
        super.paintComponents (g);
        Color transparent = new Color (0, true);
        background.setBackground(transparent);
        repaint ();
        background.setVisible(true);
        pack();
        setContentPane(background);
        background.setLayout(new FlowLayout());

        add (background);
        }    
            }











  class ShowconverterFrame  {
     public static void main (String args []) {
        new Converter ();
        }
}

Hi I am trying to figure out why this wont work... any help is appreciated! It returns with "no main class found" and that it cannot be declared as static. I just added this piece to the body and all of the sudden the whole things stops working. I have been trying to implement a JPanel in which I have an JLabel that is an image.

Foi útil?

Solução

Okay, first of all: there's more to your Converter class, right (Later edit: when I wrote this I was referring to the initial, longer code you had posted)? You have implemented all the methods in those 3 interfaces? In case you don't need them all, I suggest you take a look at Adapters. Here's a topic in which the differences between Listeners and Adapters are discussed: What is the difference between listeners and adapters?. It feels rather bad practice to implement so many interfaces with so many methods to override if you don't need all of them.

Now, if your Converter class is fully functional, a functional entry-point class should look like this:

public class ShowconverterFrame  {
     public static void main (String [] args) {
        new Converter().setVisible(true);
     }
}

Put this code in a different .java file in the same package(named ShowconverterFrame.java) and run it. Also, if you're not using an IDE, Netbeans is easy to use for beginners, it would help you a lot. :)

Aaand... the serial version id has the following purpose: What is a serialVersionUID and why should I use it? . As you can see, it has nothing to do with the answer to your question, but it's good to know.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top