J. W. Seneviratne IT 12000654 Homework 2: This assignment has been done using NetBeans IDE 7.3.1 -------------------------------------------------------------------------------------“DEMO” Button : This button will provide the demonstration as it is in the lab sheet 2. Sample images are saved in the ‘Images’ folder inside the ‘IT 12000654’ folder. All explanations of the source codes of methods are commented near each method and class. --------------------------------------------------------------------------------------SOURCE CODE //-----Homework 2--------------------------------//-----This assignment has been done using the NetBeans IDE 7.3.1 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ // J. W. Seneviratne //IT 12000654 package GUI; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.Polygon; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.JOptionPane; import javax.swing.JPanel; /** * * @author Jayani1992 */ public class GraphicObjects extends javax.swing.JFrame { /** * Creates new form GraphicObjects */ //-----Declaration of font types----Font boldBig; Font boldSmall; Font italicBig; Font italicSmall; Font plainBig; Font plainMedium; Font plainSmall; //-----Declaration of color types----Color red; Color blue; Color cyan; Color black; Color white; Color bgColor; Color gray; Color green; public GraphicObjects() { initComponents(); //-----Assignment of font types----boldBig = new Font("Arial",Font.BOLD,48); boldSmall = new Font("Arial",Font.BOLD,14); italicSmall = new Font("Arial",Font.ITALIC,8); plainBig = new Font("Lucida Calligraphy",Font.PLAIN,8); plainMedium = new Font("Arial",Font.PLAIN,14); plainBig = new Font("Times New Roman",Font.PLAIN,30); //-----Assignment of Colors----red = Color.red; blue = Color.blue; cyan = Color.cyan; black = Color.black; white = Color.white; gray = Color.gray; green = Color.green; } //-----Source code of the methods for the user inputs and buttons-------------- -----------//-----Draw Line----public void drawLines(int x, int y, int x1, int y1){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); x1 = Integer.parseInt(jTextField11.getText()); y1 = Integer.parseInt(jTextField10.getText()); gfx.drawLine(x, y, x1, y1); } //-----Draw Thick diagonal----public void drawThickLine(int x, int y,int x1,int y1){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); x1 = Integer.parseInt(jTextField11.getText()); y1 = Integer.parseInt(jTextField10.getText()); //diagonal cordinates for(int j = 0; j<5; j=j+1){ gfx.setColor(blue); gfx.drawLine(x, x1, y, y1); x = x + 1; y = y + 1; } } //-----Draw Rectangle----public void drawRectangle(int x, int y, int a, int b){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); b = Integer.parseInt(jTextField4.getText()); gfx.drawRect(x, y, a, b); } //-----Draw Sphere----- public void drawSphere(int x, int y, int a, int b){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); b = Integer.parseInt(jTextField4.getText()); gfx.drawOval(x,y,a,b); } //-----Draw Arc----public void drawArc(int x, int y, int a, int b, int c, int d){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); // width b = Integer.parseInt(jTextField4.getText()); // height c = Integer.parseInt(jTextField6.getText()); //start angle d = Integer.parseInt(jTextField7.getText()); //arc angle gfx.drawArc(x,y,a,b,10,45); } //-----Draw Polygon----public void drawPolygon(){ Graphics gfx = jPanel1.getGraphics(); Polygon p; int xPoly[] = {150,250,325,375,450,275,100}; int yPoly[] = {150,100,125,225,250,375,300}; p = new Polygon(xPoly, yPoly, xPoly.length); gfx.drawPolygon(p); } //-----Fill a Rectangle----public void fillRectangle(int x, int y, int a, int b){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); b = Integer.parseInt(jTextField4.getText()); gfx.setColor(red); gfx.fillRect(x, y, a, b); } //-----Fill a Arc----public void fillArc(int x, int y, int a, int b, int c, int d){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); // width b = Integer.parseInt(jTextField4.getText()); // height c = Integer.parseInt(jTextField6.getText()); //start angle d = Integer.parseInt(jTextField7.getText()); //arc angle gfx.setColor(blue); //can set any of the declared color types under init components(); gfx.fillArc(x,y,a,b,c,d); } //-----Fill Polygon----public void fillPolygon(){ Graphics gfx = jPanel1.getGraphics(); Polygon p; int xPoly[] = {150,200,225,375,350,275,100}; int yPoly[] = {150,100,125,275,250,375,200}; p = new Polygon(xPoly, yPoly, xPoly.length); gfx.setColor(cyan); gfx.fillPolygon(p); } //-----Draw Text----public void drawText(String text, int x, int y){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); text = jTextField5.getText(); gfx.setFont(boldBig); gfx.drawString(text, x, y); } //-----Draw Image----//-----Here user have the ability to select any picture he/she wishes to select----public void drawImage(int x, int y, int a, int b){ Graphics gfx = jPanel1.getGraphics(); x = Integer.parseInt(jTextField1.getText()); y = Integer.parseInt(jTextField2.getText()); a = Integer.parseInt(jTextField3.getText()); b = Integer.parseInt(jTextField4.getText()); //-----Give image location----jFileChooser1.showOpenDialog(this); File f = jFileChooser1.getSelectedFile(); String path = f.getAbsolutePath(); path = path.replace("\\", "/"); File f1= new File(path); try { Image im = ImageIO.read(f1); gfx.drawImage(im, x, y, a, b, rootPane); } catch (IOException ex) { Logger.getLogger(GraphicObjects.class.getName()).log(Level.SEVERE, null, ex); } } //-----Clear the painting area----public void clearPanel(JPanel pan) { pan = jPanel1; //remove all components in panel. pan.removeAll(); // refresh the panel. pan.updateUI(); } //------End of source code for user inputs--------------------------------------------------- //-----Source code for the DEMO-------------------------------------------- //-----Draw Line----public void drawLine(){ Graphics gfx = jPanel1.getGraphics(); gfx.drawLine(5, 125, 5, 175); // vertical line gfx.setColor(red); gfx.drawLine(15, 125, 50, 125); // horizontal line gfx.setColor(blue); gfx.drawLine(65, 125, 100, 175); // angular line } public void drawBelowLine(){ Graphics gfx = jPanel1.getGraphics(); gfx.setColor(black); gfx.drawLine(5, 300, 200, 300); // horizontal line } //-----Draw Thick diagonal----public void drawThickLine(){ Graphics gfx = jPanel1.getGraphics(); //diagonal cordinates int x1 = 65; int x2 = 100; for(int a = 0; a<5; a=a+1){ gfx.setColor(blue); //gfx.drawLine(x1, 10, x2, 285); gfx.drawLine(x1, 125, x2, 175); x1 = x1 + 1; x2 = x2 + 1; } } //-----Draw Rectangle----public void drawRectangle(){ Graphics gfx = jPanel1.getGraphics(); gfx.drawRect(5, 5, 50, 50); gfx.setColor(red); gfx.drawRect(65, 5, 80, 50); } //-----Fill a Rectangle----public void fillRectangle(){ Graphics gfx = jPanel1.getGraphics(); gfx.setColor(black); //can set any of the declared color types under init components(); gfx.fillRect(5, 65, 50, 50); gfx.setColor(red); //can set any of the declared color types under init components(); gfx.fillRect(65, 65, 80, 50); } //-----Draw Text----public void drawText(){ Graphics gfx = jPanel1.getGraphics(); gfx.setFont(italicSmall); //can set any of the declared font styles declared under init components(); gfx.drawString("going", 5, 298); gfx.setColor(gray); gfx.setFont(plainBig); gfx.drawString("gone", 130, 298); gfx.setColor(red); gfx.setFont(boldSmall); gfx.drawString("going", 50, 298); } //-----Draw Image 1----public void drawImage1(){ Graphics gfx = jPanel1.getGraphics(); //-----Give image location----jFileChooser1.showOpenDialog(this); File f = jFileChooser1.getSelectedFile(); String path = f.getAbsolutePath(); path = path.replace("\\", "/"); File f1= new File(path); try { Image im = ImageIO.read(f1); gfx.drawImage(im, 65, 190, 200, 200, rootPane); } catch (IOException ex) { Logger.getLogger(GraphicObjects.class.getName()).log(Level.SEVERE, null, ex); } } //-----Draw Image 2----public void drawImage2(){ Graphics gfx = jPanel1.getGraphics(); //-----Give image location----jFileChooser1.showOpenDialog(this); File f = jFileChooser1.getSelectedFile(); String path = f.getAbsolutePath(); path = path.replace("\\", "/"); File f1= new File(path); try { Image im = ImageIO.read(f1); gfx.drawImage(im, 10, 190, 50, 50, rootPane); } catch (IOException ex) { Logger.getLogger(GraphicObjects.class.getName()).log(Level.SEVERE, null, ex); } } //-----End of Source code for Demo------------------------------------------ //-----Start of Source code for Demo - Extra images------------------------//-----Draw Circle----public void drawSphere(){ Graphics gfx = jPanel1.getGraphics(); gfx.drawOval(300,20,100,100); } //-----Draw Circle----public void fillOval(){ Graphics gfx = jPanel1.getGraphics(); gfx.setColor(red); gfx.fillOval(450,20,50,100); } //-----Draw Arc----public void drawArc(){ Graphics gfx = jPanel1.getGraphics(); gfx.drawArc(300, 200, 100, 100, 180, 180); } //-----Draw Polygon----public void drawPolygon1(){ Graphics gfx = jPanel1.getGraphics(); Polygon p; int xPoly[] = {450, 460, 470, 480, 490, 500}; int yPoly[] = {360, 380, 400, 410, 420, 410}; p = new Polygon(xPoly, yPoly, xPoly.length); gfx.drawPolygon(p); } //-----Fill a Arc----public void fillArc(){ Graphics gfx = jPanel1.getGraphics(); gfx.setColor(green); //can set any of the declared color types under init components(); gfx.fillArc(420, 250, 100, 100, 90, 90); } //-----Fill Polygon----public void fillPolygon1(){ Graphics gfx = jPanel1.getGraphics(); Polygon p; int xPoly[] = {300,320,325,375,390,400,300}; int yPoly[] = {310,320,325,375,350,375,400}; p = new Polygon(xPoly, yPoly, xPoly.length); gfx.setColor(cyan); gfx.fillPolygon(p); } //-----Draw Polyline----public void drawPolyline(){ Graphics gfx = jPanel1.getGraphics(); int[] xSin = {500, 510, 520, 520, 540, 550}; int[] ySin = {410, 420, 430, 440, 450, 570}; gfx.drawPolyline(xSin, ySin, xSin.length); } //-----End of Source code for Demo - Extra images--------------------------- /** * 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() { jFileChooser1 = new javax.swing.JFileChooser(); jButton1 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jTextField6 = new javax.swing.JTextField(); jButton5 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); jTextField5 = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); jTextField7 = new javax.swing.JTextField(); jButton10 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jLabel11 = new javax.swing.JLabel(); jTextField10 = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); jTextField11 = new javax.swing.JTextField(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton1.setText("Draw Line\n"); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 130, 150, 40)); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 150, 90, -1)); jTextField2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField2ActionPerformed(evt); } }); getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 210, 90, -1)); jTextField3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField3ActionPerformed(evt); } }); getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 390, 90, -1)); jTextField4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField4ActionPerformed(evt); } }); getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 450, 90, -1)); jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton2.setText("Draw Rectangle"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 210, 150, 40)); jButton3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton3.setText("Fill Rectangle"); jButton3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton3MouseClicked(evt); } }); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 370, 150, 40)); jButton4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton4.setText("Draw Text"); jButton4.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton4MouseClicked(evt); } }); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); getContentPane().add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 490, 150, 40)); jTextField6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField6ActionPerformed(evt); } }); getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 510, 90, -1)); jButton5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton5.setText("Draw Image"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); getContentPane().add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 530, 150, 40)); jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel1.setText("2. Enter Y cordinate value :"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 190, 170, -1)); jLabel2.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel2.setText("6. Enter Height :"); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 430, 100, -1)); jLabel3.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel3.setText("1. Enter X cordinate value :"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 130, -1, -1)); jLabel4.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel4.setText("4. Enter ending Y cordinate value :"); getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 310, 210, -1)); jLabel5.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel5.setText("5. Enter Width :"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 370, 100, -1)); jButton6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton6.setText("Clean"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); getContentPane().add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 590, 70, 40)); jButton7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton7.setText("Exit"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); getContentPane().add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(940, 590, 70, 40)); jButton8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton8.setText("Draw Arc"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); getContentPane().add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 290, 150, 40)); jButton9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton9.setText("Draw Sphere"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); getContentPane().add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 250, 150, 40)); jLabel6.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N jLabel6.setText("Paint Area"); getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 20, -1, -1)); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADIN G) .add(0, 556, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADIN G) .add(0, 666, Short.MAX_VALUE) ); getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 560, 670)); jLabel7.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel7.setText("7. Enter Start angle for the Arc :"); getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 490, -1, -1)); jTextField5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField5ActionPerformed(evt); } }); getContentPane().add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 630, 90, 30)); jLabel8.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel8.setText("8. Enter arc angle for the Arc :"); getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 550, -1, -1)); jTextField7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField7ActionPerformed(evt); } }); getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 570, 90, -1)); jButton10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton10.setText("Fill Arc"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); getContentPane().add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 410, 150, 40)); jButton12.setFont(new java.awt.Font("Lucida Grande", 1, 16)); // NOI18N jButton12.setForeground(new java.awt.Color(0, 102, 204)); jButton12.setText("DEMO"); jButton12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton12ActionPerformed(evt); } }); getContentPane().add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(880, 20, 100, 50)); jButton11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton11.setText("Draw Diagonal"); jButton11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton11ActionPerformed(evt); } }); getContentPane().add(jButton11, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 170, 150, 40)); jLabel11.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel11.setText("9. Enter Text :"); getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 610, 90, 20)); jTextField10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField10ActionPerformed(evt); } }); getContentPane().add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 330, 90, -1)); jLabel12.setFont(new java.awt.Font("Lucida Grande", 1, 12)); // NOI18N jLabel12.setText("3. Enter ending X cordinate value :"); getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 250, 210, -1)); jTextField11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField11ActionPerformed(evt); } }); getContentPane().add(jTextField11, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 270, 90, -1)); jButton13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton13.setText("Fill Polygon"); jButton13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton13ActionPerformed(evt); } }); getContentPane().add(jButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 450, 150, 40)); jButton14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton14.setText("Draw Polygon"); jButton14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton14ActionPerformed(evt); } }); getContentPane().add(jButton14, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 330, 150, 40)); jButton15.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N jButton15.setForeground(new java.awt.Color(0, 102, 204)); jButton15.setText("DEMO Extra Images"); jButton15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton15ActionPerformed(evt); } }); getContentPane().add(jButton15, new org.netbeans.lib.awtextra.AbsoluteConstraints(850, 70, 170, 40)); setSize(new java.awt.Dimension(1065, 709)); setLocationRelativeTo(null); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,3,4]"); drawLines(0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6]"); drawRectangle(0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6]"); drawImage(0,0,0,0); } catch (Exception e) { e.printStackTrace(); } } private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField6.grabFocus(); } private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6,7,8]"); fillArc(0, 0, 0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates and Text. [Fill TextBoxes - 1,2 & 9]"); drawText("", 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6]"); drawSphere(0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6,7,8]"); drawArc(0, 0, 0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2,5,6]"); fillRectangle(0, 0, 0, 0); } catch (Exception e) { e.printStackTrace(); } } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearPanel(jPanel1); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextField7.setText(""); } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: drawRectangle(); fillRectangle(); drawLine(); drawImage1(); drawBelowLine(); drawText(); drawImage2(); drawThickLine(); } private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { JOptionPane.showMessageDialog(rootPane, "Enter the cordinates. [Fill TextBoxes - 1,2]"); drawThickLine(0, 0,0,0); } catch (Exception e) { e.printStackTrace(); } } private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField2.grabFocus(); } private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField11.grabFocus(); } private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField4.grabFocus(); } private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField7.grabFocus(); } private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField5.grabFocus(); } private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField3.grabFocus(); } private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jTextField10.grabFocus(); } private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: fillPolygon();// Here the user inputs are not taken. The given points are taken and filled with color. } private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: drawPolygon(); // Here the user inputs are not taken. The given points are taken. } private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: drawSphere(); fillOval(); drawArc(); drawPolygon1(); fillArc(); fillPolygon1(); drawPolyline(); } /** * @param args the command line arguments */ 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(GraphicObjects.class.getName()).log(java. util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GraphicObjects.class.getName()).log(java. util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GraphicObjects.class.getName()).log(java. util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GraphicObjects.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 GraphicObjects().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton11; private javax.swing.JButton jButton12; private javax.swing.JButton jButton13; private javax.swing.JButton jButton14; private javax.swing.JButton jButton15; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; private javax.swing.JFileChooser jFileChooser1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField10; private javax.swing.JTextField jTextField11; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; // End of variables declaration private void drawLines() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } private void drawString(String _, int i, int i0) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }