You are on page 1of 5

tobby7.co.

cc

SABTO BISOSRO // 06.10802.00167

tobby7.co.cc

Souce Code package Form; public class FrmButton extends javax.swing.JFrame { public FormButton() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code "> private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uas/Disk2.gif"))); jButton1.setText(" Save"); jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uas/Find.gif"))); jButton2.setText("Cari"); jButton3.setFont(new java.awt.Font("Tahoma", 1, 11)); jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uas/delete.gif"))); jButton3.setText("Delete"); jButton4.setFont(new java.awt.Font("Tahoma", 1, 11)); jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uas/print.gif"))); jButton4.setText("Print"); jButton5.setFont(new java.awt.Font("Tahoma", 1, 11)); jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uas/exit.gif"))); jButton5.setText("Exit"); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); jLabel2.setText("NIM : 06.10802.00104"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()
pdfMachine A pdf writer that produces quality PDF files with ease! Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across nearly all Windows platforms, if you can print from a windows application you can use pdfMachine. Get yours now!

to

bb y7 .

co .

cc

tobby7.co.cc

.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel1) .addComponent(jLabel2)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))) .addGap(17, 17, 17) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addContainerGap(83, Short.MAX_VALUE)) ); pack(); }// </editor-fold> public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FrmButton().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2;
pdfMachine A pdf writer that produces quality PDF files with ease! Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across nearly all Windows platforms, if you can print from a windows application you can use pdfMachine. Get yours now!

to

bb y7 .

co .

cc

tobby7.co.cc

// End of variables declaration }

Membuat komponen - Menampilkan Image


package Form; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JImage extends JLabel { private ImageIcon image; private int state; public static final int NORMAL=0,FIT=1,SCALE=2; public JImage() { this(null); } public JImage(ImageIcon image) { this(image,NORMAL); } public JImage(ImageIcon image, int state) { this.state = state; setImage(image); } public void setState(int state) { this.state = state; repaint(); } public int getState() { return state; } public void setImage(ImageIcon image) { this.image = image; repaint(); } public ImageIcon getImage() { return image; } public void paintComponent(Graphics g) { super.paintComponent(g); if(image!=null && image.getImage()!=null) switch(state) { case NORMAL : g.drawImage(image.getImage(),0,0,null); break; case FIT : g.drawImage(image.getImage(),0,0,getSize().width,getSize().height,null); break; case SCALE : drawScale(g); } } private void drawScale(Graphics g) { Image im = image.getImage(); int compWidth = getWidth(), compHeight = getHeight(), imageWidth = im.getWidth(null), imageHeight = im.getHeight(null); double scaleFactor = Math.min((double)compWidth/imageWidth, (double)compHeight/imageHeight); int x = (int)((compWidth - imageWidth*scaleFactor)/2); int y = (int)((compHeight - imageHeight*scaleFactor)/2); //g.drawImage(im,x,y,(int)(imageWidth*scaleFactor),(int)(imageHeight*scaleFactor),null); //g.drawImage(im,x,y,100,100,null);
pdfMachine A pdf writer that produces quality PDF files with ease! Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across nearly all Windows platforms, if you can print from a windows application you can use pdfMachine. Get yours now!

to

bb y7 .

co .

cc

tobby7.co.cc

g.drawImage(im,50,50,100,100,null); } } Membuat komponen - Combobox

Source Code komponen package Frm; import javax.swing.*; public class Combo extends JComboBox { public Combo () { setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Laki laki", "Perempuan" })); } }

FORM

public class Frmextends javax.swing.JFrame { public Frm() { initComponents(); }

private void initComponents() { jButton1 = new javax.swing.JButton(); cb1 = new cbb.cb(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("Pilih"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(cb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
pdfMachine A pdf writer that produces quality PDF files with ease! Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across nearly all Windows platforms, if you can print from a windows application you can use pdfMachine. Get yours now!

to

bb y7 .

co .

package Frm; import javax.swing.*;

cc

tobby7.co.cc

.addContainerGap(24, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(11, 11, 11) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1) .addComponent(cb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(63, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String data = (String) cb1.getSelectedItem(); String sub2 =data.substring(0,1); JOptionPane.showMessageDialog(null,sub2); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Frm().setVisible(true); } }); } // Variables declaration - do not modify private cbb.Combo Combo1; private javax.swing.JButton jButton1; // End of variables declaration }

pdfMachine A pdf writer that produces quality PDF files with ease! Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across nearly all Windows platforms, if you can print from a windows application you can use pdfMachine. Get yours now!

to

bb y7 .

co .

cc

You might also like