adapun Source Codenya adalah sebagai berikut :
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;
import javax.swing.JPanel;
public class grafkom3 extends javax.swing.JFrame {
/** Creates new form grafika_3 */
public grafkom3() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
bt_derajat_1 = new javax.swing.JButton();
bt_derajat_2 = new javax.swing.JButton();
bt_derajat_3 = new javax.swing.JButton();
bt_spline = new javax.swing.JButton();
bt_kontrol = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
);
bt_derajat_1.setText("Derajat 1");
bt_derajat_1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_derajat_1ActionPerformed(evt);
}
});
bt_derajat_2.setText("Derajat 2");
bt_derajat_2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_derajat_2ActionPerformed(evt);
}
});
bt_derajat_3.setText("Derajat 3");
bt_derajat_3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_derajat_3ActionPerformed(evt);
}
});
bt_spline.setText("Spline");
bt_spline.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_splineActionPerformed(evt);
}
});
bt_kontrol.setText("Titik Kontrol");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(bt_kontrol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bt_spline, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bt_derajat_3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bt_derajat_2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bt_derajat_1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(41, 41, 41))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addComponent(bt_derajat_1)
.addGap(18, 18, 18)
.addComponent(bt_derajat_2)
.addGap(18, 18, 18)
.addComponent(bt_derajat_3)
.addGap(18, 18, 18)
.addComponent(bt_spline)
.addGap(18, 18, 18)
.addComponent(bt_kontrol))
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(20, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void bt_derajat_1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jPanel1 = new Derajad_1();
jPanel1.repaint();
jScrollPane1.setViewportView(jPanel1);
jPanel1.setAutoscrolls(true);
}
private void bt_derajat_2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jPanel1 = new Derajad_2();
jPanel1.repaint();
jScrollPane1.setViewportView(jPanel1);
jPanel1.setAutoscrolls(true);
}
private void bt_derajat_3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jPanel1 = new Derajad_3();
jPanel1.repaint();
jScrollPane1.setViewportView(jPanel1);
jPanel1.setAutoscrolls(true);
}
private void bt_splineActionPerformed(java.awt.event.ActionEvent evt) {
jPanel1 = new spline();
jPanel1.repaint();
jScrollPane1.setViewportView(jPanel1);
jPanel1.setAutoscrolls(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new grafkom3().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bt_derajat_1;
private javax.swing.JButton bt_derajat_2;
private javax.swing.JButton bt_derajat_3;
private javax.swing.JButton bt_kontrol;
private javax.swing.JButton bt_spline;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
class Derajad_1 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
Shape lurus = new Line2D.Double(200,250, 300, 50);
g2.draw(lurus);
}
}
class Derajad_2 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
Shape kuadrat = new QuadCurve2D.Double(100,150,175,75,300,150);
g2.draw(kuadrat);
}
}
class Derajad_3 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
Shape kubik = new CubicCurve2D.Double(50,150,150, 100,200,250,300,150);
g2.draw(kubik);
}
}
class spline extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.draw(new CubicCurve2D.Double(30, 140, 50, 10, 120, 180, 190, 30));
g2.draw(new QuadCurve2D.Double(190, 30, 220, 10, 230, 60));
}
}
Tidak ada komentar:
Posting Komentar