Pertama,Kami membuat Tampilan JFrame sederhana
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.SocketTimeoutException; /** * Created by putriramadannia_pc on 4/5/2017. */public class Notepad extends JFrame { public Notepad() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { //menentukan tampilan dari window//tampilan dari sistem nya e.printStackTrace(); } catch(InstantiationException e){ e.printStackTrace(); } catch(IllegalAccessException e){ e.printStackTrace(); } catch(UnsupportedLookAndFeelException e){ e.printStackTrace(); } JPanel panel = (JPanel) this.getContentPane(); //cara ngambil content jframa GridLayout gridLayout = new GridLayout(0, 2);//layout manager panel.setLayout(gridLayout); JTextField field = new JTextField(); //dia buat text field dan area field=satu baris,area banyak baris JTextArea textArea = new JTextArea(); //layup untuk mengatur panel.add(field); panel.add(textArea); this.setTitle("Notepad"); JMenuBar menuBar = new JMenuBar(); JMenu file = new JMenu("File"), view = new JMenu("View"); JMenuItem open = new JMenuItem("Open"), save = new JMenuItem("Save"), saveAs = new JMenuItem("Save As"); JMenu font = new JMenu("Font"); JMenuItem size14 = new JMenuItem("14"); JMenuItem size16 = new JMenuItem("16"); JMenuItem size18 = new JMenuItem("18"); file.add(open); file.add(save); file.add(saveAs); //Menu untuk Test Alert Box JMenuItem test = new JMenuItem("Test"); test.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(Notepad.this, "Jangan" + "ada sianida diantara kita.", "AWAS!", JOptionPane.WARNING_MESSAGE); String jawaban = JOptionPane.showInputDialog(Notepad.this, "Apa Ajawaban Anda?", "Hai sayang!", JOptionPane.WARNING_MESSAGE ); System.out.println(jawaban); } }); view.add(test); view.add(font); font.add(size14); font.add(size16); font.add(size18); menuBar.add(file); menuBar.add(view); this.setJMenuBar(menuBar); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); //mENGESET uKURAN mINIIMUM JFrame this.pack(); //komponen nya jadi 1 this.setMinimumSize(this.getPreferredSize()); //mengupdate ukuran yang pas untuk window itu this.setVisible(true); } public static void main(String[] args) { Notepad notepad = new Notepad(); } }
saat di run
Tidak ada komentar:
Posting Komentar