You are on page 1of 4

import import import import import import import import import import import import import import import

import import import import import

java.awt.Color; java.awt.FlowLayout; java.awt.Font; java.awt.event.ActionEvent; java.awt.event.ActionListener; java.io.ByteArrayOutputStream; java.io.IOException; java.io.InputStream; java.net.MalformedURLException; java.net.URL; java.net.URLConnection; javax.swing.JButton; javax.swing.JFrame; javax.swing.JLabel; javax.swing.JOptionPane; javax.swing.JRadioButton; javax.swing.JRadioButtonMenuItem; javax.swing.JScrollPane; javax.swing.JTextField; javax.swing.JTextPane;

public class MyGoogle { public static void main(String[] args) { final JFrame frame = new JFrame(" == PIS 10-02 VERAMITA S == "); frame.setSize(450, 200); frame.setTitle("My Google: " + frame.getWidth()); frame.setSize(450, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setAlwaysOnTop(true); frame.getContentPane().setBackground(Color.DARK_GRAY); // frame.setUndecorated(true); frame.setLocationRelativeTo(null); frame.setLayout(new FlowLayout()); final JLabel label = new JLabel("ENTER THE URL"); label.setFont(new Font("", 10, 40));// 10->12, 40->80 label.setForeground(Color.MAGENTA); frame.add(label); final JTextField field = new JTextField(25); field.setToolTipText("zwww.facebook.com"); frame.add(field); JButton button = new JButton("Search !"); button.setForeground(Color.BLACK); button.setBackground(Color.ORANGE); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (field.getText().equals("")) { System.out.println("tidak ada teks yang ditulis!"); // JOptionPane.showConfirmDialog(frame, label, "nothing", // 1); JOptionPane.showMessageDialog(frame, lab

//

el, "Judul Pesannya", 1);// ---> maksudnya 0=x, 1=i, // 2=!, 3=? } else { // frame.setVisible(false); JFrame frame2 = new JFrame("Frame Hasil" ); // frame2.setDefaultCloseOperation(JFram e.EXIT_ON_CLOSE); frame2.setSize(600, 400); frame2.setLocationRelativeTo(frame); final JTextPane textPane = new JTextPane (); final JScrollPane scrollPane = new JScro llPane(textPane); panggilKoneksi(field, textPane); frame2.add(scrollPane); frame2.setVisible(true); JLabel label = new JLabel (" File Edit View "); frame.add(label); } } private void panggilKoneksi(final JTextField field, final JTextPane textPane) { try { URL url = new URL(field.getText()); URLConnection con = url.openConnection() ; InputStream is = con.getInputStream(); ByteArrayOutputStream os = new ByteArray OutputStream(); byte[] b = new byte[10]; int len; while ((len = is.read(b, 0, b.length)) ! = -1) { os.write(b, 0, len); } textPane.setText(new String(os.toByteArr ay())); os.close(); is.close(); } catch (MalformedURLException e) { // e.printStackTrace();

// System.out.println("terjadi kesalahan penulisan url!"); JLabel label2 = new JLabel("Salah Tulis di URL."); JOptionPane.showMessageDialog(frame, lab el2, "Kesalahan Tulis", 1); } catch (IOException e) { // e.printStackTrace(); // System.out.println("terjadi kesalahan penulisan url!"); JLabel label3 = new JLabel("Salah Tulis di URL ini."); JOptionPane.showMessageDialog(frame, lab el3, "Kesalahan Tulis", 0); } } }); frame.add(button); JRadioButton radioButton = new JRadioButton(" penelusuran dengan web "); frame.add(radioButton); JRadioButton radioButton2 = new JRadioButton(" penelusuran dengan gambar "); frame.add(radioButton2);

JRadioButtonMenuItem item = new JRadioButtonMenuItem("choose 1") ; item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("helooo..."); } }); frame.add(item); JRadioButtonMenuItem item2 = new JRadioButtonMenuItem("choose 2" ); item2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("test...."); } }); frame.add(item2); JRadioButtonMenuItem item3 = new JRadioButtonMenuItem("choose 3" ); item3.addActionListener(new ActionListener() { @Override

public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("test heloo.."); } }); frame.add(item3); JRadioButtonMenuItem item4 = new JRadioButtonMenuItem("choose 4" ); item4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.out.println("terima kasih.."); System.exit(0); } }); frame.add(item4); frame.setVisible(true); } }

You might also like