I have this problem in a program which changes panels in a JFrame. I know how to use action listeners, but I already have a component I use for my image. Can someone help me?
package javaapplication3;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class JavaApplication3 extends Component {
BufferedImage img;
public JavaApplication3(){
try {img = ImageIO.read(new File("a.jpg"));}catch (IOException e) {}}
public static void main(String[] args) {
JFrame frame = new JFrame();
JButton b = new JButton();
JPanel p = new JPanel();
JPanel p1 = new JPanel();
p.add(b);
p1.add(new JavaApplication3());
frame.add(p);
frame.setSize(150,150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}}
You can have both an extension and implmentation of multiple interfaces for a class so it would be
For a reference on interfaces in java
http://docs.oracle.com/javase/tutorial/java/concepts/interface.html
Vs
Inheritance of classes in java
http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html