Я хочу добавить компоненты внутри JDialog Box в Swing, не расширяя внутренний класс, который расширяет JDialog, как показано в приведенном ниже коде. SimpleAboutDialog - это внутренний класс внутри моего класса, основанный на некоторых условиях, когда я создаю экземпляр его класса, чтобы получить блок JDialog с JLabels. но я не хочу использовать объект этого
package com.project.swings.layout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
public class PopUpMenu{
JPopupMenu Pmenu;
JMenuItem menuItem;
public static void main(String[] args) {
PopUpMenu p = new PopUpMenu();
}
public PopUpMenu(){
JFrame frame = new JFrame("Creating a Popup Menu");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Pmenu = new JPopupMenu();
menuItem = new JMenuItem("Cut");
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Cut")){
SimpleAboutDialog sad=new SimpleAboutDialog(new JFrame());
sad.setSize(200, 200);
sad.setVisible(true);
}
}
});
Pmenu.add(menuItem);
menuItem = new JMenuItem("Copy");
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Copy")){
JOptionPane.showInputDialog(null, "Please choose a name", "Example 1",
JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Amanda",
"Colin", "Don", "Fred", "Gordon", "Janet", "Jay",
"Joe", "Judie", "Kerstin", "Lotus", "Maciek", "Mark",
"Mike", "Mulhern", "Oliver", "Peter", "Quaxo", "Rita",
"Sandro", "Tim", "Will" }, "Joe");
}
}
});
Pmenu.add(menuItem);
menuItem = new JMenuItem("Paste");
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Paste")){
String string[]={"Sam","Samarth","Mourya"};
JComboBox combo=new JComboBox();
JOptionPane.showInputDialog(new JFrame(),"Combo","Dialog",1,null,string ,"Mourya");
}
}
}
);
Pmenu.add(menuItem);
menuItem = new JMenuItem("Delete");
Pmenu.add(menuItem);
menuItem = new JMenuItem("Undo");
Pmenu.add(menuItem);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Cut")){
SimpleAboutDialog sad=new SimpleAboutDialog(new JFrame());
sad.setSize(200, 200);
sad.setVisible(true);
}
}
});
frame.addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent Me){
if(Me.isPopupTrigger()){
Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
}
}
});
frame.setSize(400,400);
frame.setVisible(true);
}
private class SimpleAboutDialog extends JDialog {
public SimpleAboutDialog(JFrame parent) {
super(parent, "About Dialog", true);
Box b = Box.createVerticalBox();
b.add(Box.createGlue());
b.add(new JLabel("J"));
b.add(new JButton("g"));
b.add(Box.createGlue());
getContentPane().add(b, "Center");
JPanel p2 = new JPanel();
JButton ok = new JButton("Ok");
p2.add(ok);
getContentPane().add(p2, "South");
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
setVisible(false);
}
});
setSize(250, 150);
}
}
}