Skip to content

Instantly share code, notes, and snippets.

@resarahadian
Created May 13, 2012 03:57
Show Gist options
  • Save resarahadian/2677989 to your computer and use it in GitHub Desktop.
Save resarahadian/2677989 to your computer and use it in GitHub Desktop.
Program JPopUpMenu
/*
* @ author Resa C.R
*/
import javax.swing.*;
import java.awt.*;
import java.awt.*;
public class FileBaru extends JInternalFrame
{
Container konten = getContentPane();
private JLabel lblNama = new JLabel("Nama : ");
private JTextField txtNama = new JTextField();
private JLabel lblAlamat = new JLabel("Alamat : ");
private JTextField txtAlamat = new JTextField();
private JLabel lblEmail = new JLabel("Email : ");
private JTextField txtEmail = new JTextField();
private JButton btnSimpan = new JButton("Simpan");
private JButton btnBatal = new JButton("Batal");
private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel();
//Konstruktor
public FileBaru()
{
super("Data",true,true,false,true);
setSize(500,500);
setVisible(true);
setLocation(130,50);
panel1.setLayout(new GridLayout(3,2));
panel1.setBorder(BorderFactory.createTitledBorder("Silahkan isi Data"));
panel1.add(lblNama);
panel1.add(txtNama);
panel1.add(lblAlamat);
panel1.add(txtAlamat);
panel1.add(lblEmail);
panel1.add(txtEmail);
panel2.add(btnSimpan);
panel2.add(btnBatal);
panel3.setLayout(new BorderLayout());
panel3.add(panel1,BorderLayout.NORTH);
panel3.add(panel2,BorderLayout.SOUTH);
konten.add(panel3);
}//Akhir Kosstruktor
}
/*
* @ author Resa C.R
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PopUp extends JFrame
{
Container konten = getContentPane();
private JDesktopPane desktop = new JDesktopPane();
private JPopupMenu popUp = new JPopupMenu();
private JMenu menuNew = new JMenu("New");
private JMenuItem miFile = new JMenuItem("Form");
private JMenuItem miOther = new JMenuItem("Other...");
private JMenuItem miOpen = new JMenuItem("Open");
private JMenuItem miExit = new JMenuItem("Exit");
//Konstruktor
public PopUp()
{
setTitle("JPopUp");
setVisible(true);
setSize(700,600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
menuNew.add(miFile);
menuNew.add(miOther);
popUp.add(menuNew);
popUp.add(miOpen);
popUp.add(miExit);
konten.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent me)
{
//Membuat aksi Klik Kanan desktop
if(me.getButton() == 3)
{
popUp.show(me.getComponent(),me.getX(),me.getY()); //Menampilkan menu di PopUp
}
}
});
miFile.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent act)
{
desktop.add(new FileBaru());
}
});
konten.add(desktop);
}//Akhir Kostruktor
public static void main(String[] ar)
{
//Look and feel dengan JTattoo
try
{
com.jtattoo.plaf.graphite.GraphiteLookAndFeel.setTheme("Blue-Large-Font", "PopUp", "Program");
UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
new PopUp();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment