Académique Documents
Professionnel Documents
Culture Documents
Practical Task #2
FCSIT
International Student
Gustavo Eduardo Garcia Sanchez
Stud. ID Nr. 171AMB136
1. Task of Work
During class you will be given the first half of the Bresenham algorithm that can draw
straight horizontal lines (where dx>dy), complete this algorithm so that it could draw
straight vertical lines (where dy>dx). The coordinates of the first and last point of the
line are defined using 4 text fields.
2. Programming Code
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
canvas = new MyCanvas(this.jPanel1);
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Start");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextFieldX1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldX1ActionPerformed(evt);
}
});
jLabel1.setText("X1:");
jLabel2.setText("Y1:");
jLabel3.setText("X2:");
jLabel4.setText("Y2:");
jButton2.setText("Clean");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
pack();
}// </editor-fold>
int xn = x1;
int yn = y1;
int xi, yi;
Figure 2. Drawing of one straight horizontal line and other with dx > dy. The coordinates are defined in the 4 text fields.
Figure 3. Drawing of one straight vertical line and other with dy > dx. The coordinates are defined in the 4 text fields.