hapir sama dengan tulisan sebelumnya. kali ini tulisan berjalan secara horizontal dan vertikal. design formnya kaya gini
source Codenya:
package sister3;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jazilah
*/
public class no2 extends javax.swing.JFrame implements Runnable {
boolean horz = false;
int x, y;
boolean kanankiri = true;
boolean atasbawah = true;
boolean arah;
public no2() {
initComponents();
}
private void berhentiActionPerformed(java.awt.event.ActionEvent evt) {
horz = true;
}
private void lanjutActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(this).start();
horz = false;
}
private void vertikalActionPerformed(java.awt.event.ActionEvent evt) {
arah = false;
}
private void horizontalActionPerformed(java.awt.event.ActionEvent evt) {
arah = true;
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(no2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(no2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(no2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(no2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new no2().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton berhenti;
private javax.swing.JButton horizontal;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton lanjut;
private javax.swing.JButton vertikal;
// End of variables declaration
public void run() {
while (horz == false) {
if (arah == true) {
if (kanankiri == true) {
x++;
if (x == 200) {
kanankiri = false;
}
} else {
x--;
if (x == 10) {
kanankiri = true;
}
}
} else {
if (atasbawah == true) {
y++;
if (y == 200) {
atasbawah = false;
}
} else {
y--;
if (y == 0) {
atasbawah = true;
}
}
}
jLabel2.setBounds(x, y, 400, 40);
System.out.println("" + x);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
Logger.getLogger(Tugas1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
source code lengkapnya bisa di download di sini
Kamis, 20 Maret 2014
Tulisan Berjalan Horizontal Berbasis GUI di Java (Thread)
yuuuuhuuu praktikum lagi,,, bisa nulis lagi
langsung aja. soal pertama praktikum SISTER (Sistem Terdistribusi) pertemuan ke 3 ini adalah:
membuat tulisan berjalan secara horizontal dengan berbasis GUI. didalamnya terdapat tombol untuk menghentikan maupun menjalankan tulisan tersebut. screenchot programnya kaya gini:
langkah pertama buat dulu tampilan di JFrame Form kaya diatas. komponen-komponen dari form tersebut kita kasih nama
jLabel2: Jalan Jalan Siang
berhenti: tombol Berhenti
lanjut: tombol Lanjutkan
Kemudian ketikkan sourcecode kaya dibawah ini:
package sister3;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jazilah
*/
public class no1 extends javax.swing.JFrame implements Runnable{
boolean horz = false;
int x, y, h, w;
boolean kanankiri = true;
public no1() {
initComponents();
}
@SuppressWarnings("unchecked")
private void berhentiActionPerformed(java.awt.event.ActionEvent evt) {
horz = true;
}
private void lanjutActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(this).start();
horz = false;
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new no1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton berhenti;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton lanjut;
// End of variables declaration
public void run() {
while (horz == false) {
if (kanankiri == true) {
x++;
if (x == 200) {
kanankiri = false;
}
} else {
x--;
if (x == 0) {
kanankiri = true;
}
}
jLabel2.setBounds(x, 20, 400, 40);
System.out.println("x = "+x);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
Logger.getLogger(Tugas1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
sourceCode lengkapnya bisa di unduh di sini
langsung aja. soal pertama praktikum SISTER (Sistem Terdistribusi) pertemuan ke 3 ini adalah:
membuat tulisan berjalan secara horizontal dengan berbasis GUI. didalamnya terdapat tombol untuk menghentikan maupun menjalankan tulisan tersebut. screenchot programnya kaya gini:
langkah pertama buat dulu tampilan di JFrame Form kaya diatas. komponen-komponen dari form tersebut kita kasih nama
jLabel2: Jalan Jalan Siang
berhenti: tombol Berhenti
lanjut: tombol Lanjutkan
Kemudian ketikkan sourcecode kaya dibawah ini:
package sister3;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jazilah
*/
public class no1 extends javax.swing.JFrame implements Runnable{
boolean horz = false;
int x, y, h, w;
boolean kanankiri = true;
public no1() {
initComponents();
}
@SuppressWarnings("unchecked")
private void berhentiActionPerformed(java.awt.event.ActionEvent evt) {
horz = true;
}
private void lanjutActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(this).start();
horz = false;
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(no1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new no1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton berhenti;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton lanjut;
// End of variables declaration
public void run() {
while (horz == false) {
if (kanankiri == true) {
x++;
if (x == 200) {
kanankiri = false;
}
} else {
x--;
if (x == 0) {
kanankiri = true;
}
}
jLabel2.setBounds(x, 20, 400, 40);
System.out.println("x = "+x);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
Logger.getLogger(Tugas1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
sourceCode lengkapnya bisa di unduh di sini
Langganan:
Postingan (Atom)