import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
/**
*
* @author Mohhax
*/
public class My_Google extends JFrame{
public static void main(String[]args){
final JFrame call = new JFrame("Google");
call.setLocationRelativeTo(null);
call.setLayout(new FlowLayout());
call.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
call.setSize(620,350);
call.setResizable(false);
JLabel google = new JLabel(new ImageIcon("src/images/Google.png"));
final JTextField text = new JTextField(40);
JButton search = new JButton("Search",new ImageIcon("src/images/search_.png"));
JButton web = new JButton("Web");
JButton images = new JButton("Images");
JButton iklan = new JButton("Iklan");
final JLabel message = new JLabel("Tidak ada text yang tertulis!");
search.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if (text.getText().equals("")) {
JOptionPane.showMessageDialog(call, message, "Message", 1);
call.add(message);
}else{
JFrame show_search = new JFrame("Search");
show_search.setSize(600,450);
show_search.setLocationRelativeTo(null);
final JTextPane textPane = new JTextPane();
final JScrollPane scrollPane = new JScrollPane();
show_search.add(scrollPane);
show_search.setVisible(true);
}
}
private void connection_call(final JTextField text, final JTextPane textPane) throws MalformedURLException, IOException {
try {
URL url = new URL(text.getText());
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
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.toByteArray()));
} catch(MalformedURLException e){
JLabel message2 = new JLabel("Salah Tulis!");
JOptionPane.showMessageDialog(call, message2, "Message", 1);
call.add(message2);
} catch(IOException e){
JLabel message3 = new JLabel("Salah Tulis!");
JOptionPane.showMessageDialog(call, message3, "Message", 0);
call.add(message3);
}
}
});
call.add(google);
call.add(text);
call.add(search);
call.add(web);
call.add(images);
call.add(iklan);
call.setVisible(true);
}
}
Tidak ada komentar:
Posting Komentar