Tutorial Pemrograman Java, Memasukan gambar kedalam Frame program
package pelajaranjava;
import java.awt.*;
import java.awt.event.*;
public class AlasGambar extends Frame{
Toolkit ambilGambar=getToolkit();
AlasGambar(){
super("Gambar Souljaboy");
addWindowListener(JE);
setSize(500,260);
setVisible(true);
}
public void paint(Graphics Gambar){
Image img = ambilGambar.getImage("C:/Souljaboy.jpg");
Gambar.drawImage(img, 150, 50, 200, 200, this);
}
JendelaEvent JE = new JendelaEvent();
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
}
}
-------------------------------------------------------------------
import java.awt.event.*;
Toolkit ambilGambar=getToolkit();
AlasGambar(){
super("Gambar Souljaboy");
addWindowListener(JE);
setSize(500,260);
setVisible(true);
}
Image img = ambilGambar.getImage("C:/Souljaboy.jpg");
Gambar.drawImage(img, 150, 50, 200, 200, this);
}
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
}
package pelajaranjava;
public class Main {
public static void main(String[] args) {
AlasGambar ag = new AlasGambar();
}
}
Tutorial Pemrograman Java, Membuat Objek Kotak
package pelajaranjava;
import java.awt.*;
import java.awt.event.*;
public class ObjekKotak extends Frame{
ObjekKotak(){
super("Menggambar Objek Kotak");
addWindowListener(JE);
setSize(310,150);
setVisible(true);
}
public void paint(Graphics Gambar){
Gambar.setColor(Color.RED);
Gambar.drawRect(50, 50, 70, 70);
Gambar.fillRect(200, 50, 70, 70);
}
JendelaEvent JE = new JendelaEvent();
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
}
-----------------------------------------------------------
import java.awt.event.*;
addWindowListener(JE);
setSize(310,150);
setVisible(true);
Gambar.setColor(Color.RED);
Gambar.fillRect(200, 50, 70, 70);
}
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
----------^^^^^^^^^^^^^^^^^^^^^-----------
package pelajaranjava;
public class Main {
public static void main(String[] args) {
ObjekKotak ok = new ObjekKotak();
}
}
Tutorial Pemrograman Java, Membuat Objek Lingkaran
package pelajaranjava;
import java.awt.*;
import java.awt.event.*;
public class ObjekLingkaran extends Frame{
ObjekLingkaran(){
super("Menggambar Objek Lingkaran");
addWindowListener(JE);
setSize(310,150);
setVisible(true);
}
public void paint(Graphics Gambar){
Gambar.setColor(Color.RED);
Gambar.drawOval(50, 50, 70, 70);
Gambar.fillOval(200, 50, 70, 70);
}
JendelaEvent JE = new JendelaEvent();
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
}
-----------------------------------------------------------
import java.awt.event.*;
addWindowListener(JE);
setSize(310,150);
setVisible(true);
Gambar.setColor(Color.RED);
Gambar.drawOval(50, 50, 70, 70);
Gambar.fillOval(200, 50, 70, 70);
}
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
----------^^^^^^^^^^^^^^^^^^^^^-----------
package pelajaranjava;
public class Main {
public static void main(String[] args) {
ObjekLingkaran ol = new ObjekLingkaran();
}
}
Tutorial Pemrograman Java, Operasi Matematika
>> Sabtu, 20 Juni 2009
import java.net.*;
public class OperasiMatematik {
public static void main(String[] args) {
Integer angkaPertama = 5;
Integer angkaKedua = 5;
Integer hasilTambah = angkaPertama + angkaKedua;
Integer hasilKurang = angkaPertama - angkaKedua;
Integer hasilKali = angkaPertama * angkaKedua;
Integer hasilBagi = angkaPertama / angkaKedua;
System.out.println("Hasil dari 5 ditambah dengan 5 adalah"+hasilTambah);
System.out.println("Hasil dari 5 dikurang dengan 5 adalah"+hasilKurang);
System.out.println("Hasil dari 5 dikali dengan 5 adalah"+hasilKali);
System.out.println("Hasil dari 5 dibagi dengan 5 adalah"+hasilBagi);
}
}
Tutorial Pemrograman Java, Query
import java.net.*;
public class AmbilQuery{
public static void main(String[] args) {
try{
URL url = new URL("http://www.domainsaya.com/tambahData.php?nama=anhar&umur=15");
String protokol = url.getQuery();
System.out.println(protokol);
}catch(Exception ue){
}
}
}
Tutorial Pemrograman Java, Mengambil port dari URL
import java.net.*;
public class AmbilPort {
public static void main(String[] args) {
try{
URL url = new URL("http://www.yahoo.com");
Integer protokol = url.getPort();
System.out.println(protokol);
}catch(Exception ue){
}
}
}
0 komentar:
Posting Komentar