import javax.swing.JButton; import javax.swing.JFrame; public class testheritation extends JFrame implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; JButton testOk=new JButton("toto"); public JButton getButton() { testOk.addActionListener(this); return testOk; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("super classe"); } package mainPackage; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MainClass extends testheritation implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; public MainClass() { super(); add(getButton()); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MainClass mc=new MainClass(); mc.pack(); mc.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // Appel de la méthode mère : super.actionPerformed(e); System.out.println("sous Classe"); } }
import javax.swing.JButton; import javax.swing.JFrame; public class testheritation extends JFrame implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; JButton testOk=new JButton("toto"); public JButton getButton() { testOk.addActionListener(this); return testOk; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("super classe"); } package mainPackage; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MainClass extends testheritation { private static final long serialVersionUID = 1L; private class ActionListen implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("sous Classe"); } } public MainClass() { super(); add(getButton()); getButton.addActionListener(new ActionListen()); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MainClass mc=new MainClass(); mc.pack(); mc.setVisible(true); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question