我想将 J-frame 的对象从Action Listener发送到另一个类的方法。所以被调用方法的内容在同一帧中。但我无法在同一帧中获得该方法。请帮助..
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents(this);
}
public void initComponents(NewJFrame ob) {
scrollbar1 = new java.awt.Scrollbar();
jScrollBar1 = new javax.swing.JScrollBar(); //all the GUI**inside this method i created button(jMenuItem2) and called method of another class in action listener as shown below**
jMenuItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg) {
MenuExp obb=new MenuExp();
// System.out.println(arg.getSource().getClass());
obb.cross(ob);
} });
}
public class MewExp{
public void cross(NewJFrame obbb)
{
//final JFrame frame = new JFrame("JToolBar Demo");
JToolBar toolbar = new JToolBar();
JButton btnCalendar = new JButton(new ImageIcon("C:\\Users\\vishnu\\Documents\\NetBeansProjects\\imazer\\src\\imazer\\kick.jpg"));
btnCalendar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(, "Calendar clicked");
}
});
toolbar.add(btnCalendar);
// setLayout(new BorderLayout());
obbb.getContentPane().add(toolbar, BorderLayout.WEST);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setSize(200, 500);
//setVisible(true);
//System.out.print(obbb);
obbb.add(toolbar);
// setVisible(true);
// obbb.pack();
}
答案 0 :(得分:0)
假设Menu
是另一个类
该类有方法changeContent(JFrame sameFrame)
然后
Menu menu=new Menu();
menu.changeContent(this);
将为你完成这项工作。