cambeme
Giới tính : Cung : Con giáp : Bài gửi : 174 Điểm : 5285 Thanks : 0 Sinh nhật : 05/12/1991 Ngày gia nhập : 25/03/2011 Tuổi : 32 Đến từ : Thành phố Hồ Chí minh Nghề nghiệp/ước mơ : IT Tâm trạng : Hưng phắn Châm ngôn sống : Không có gì quý hơn hột vịt thịt kho!
Cao nhân tắt thở vô phương trị!
| Tiêu đề: Assignment 03 – Swing Graphic 29/3/2011, 18:51 | |
| | 29/3/2011, 18:51 Assignment 03 – Swing Graphic | | | Bài 1: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro01_T094054 extends JFrame { // constructor public cAss03Pro01_T094054() { // set size width=300, height= 300 setSize(300, 300); // set background color setBackground(Color.white); // set title setTitle("Line and Arc"); }
// paint function public void paint(Graphics g) { g.drawLine(50, 150, 250, 150); g.drawLine(150, 50, 150, 250); g.drawArc(50, 50, 200, 200, 270, 270); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro01_T094054 mainWindow = new cAss03Pro01_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 2: - Code:
-
import javax.swing.JFrame; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro02_T094054 extends JFrame { // constructor public cAss03Pro02_T094054() { // set size width=400, height= 400 setSize(400, 400); // set background color setBackground(Color.white); // set title setTitle("Circe of Life"); }
// paint function public void paint(Graphics g) { int x = 100, y = 100; // draw the round outside g.setColor(Color.RED); g.fillOval(x - 25, y - 25, x + 150, y + 150); // draw the round inside g.setColor(Color.WHITE); g.fillOval(x + 10, y + 10, x + 80, y + 80); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro02_T094054 mainWindow = new cAss03Pro02_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 3: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro03_T094054 extends JFrame { // constructor public cAss03Pro03_T094054() { // set size width=400, height= 400 setSize(400, 400); // set background color setBackground(Color.white); // set title setTitle("Four Corner"); }
// paint function public void paint(Graphics g) { int a = 100; // draw two big lines g.drawLine(0, 2 * a, 4 * a, 2 * a); g.drawLine(2 * a, 0, 2 * a, 4 * a); // draw four rounds g.drawArc(2 * a / 5, a / 2, 6 * a / 5, 6 * a / 5, 360, 360); g.drawArc(12 * a / 5, 230, 6 * a / 5, 6 * a / 5, 360, 360); g.drawArc(12 * a / 5, a / 2, 6 * a / 5, 6 * a / 5, 360, 360); g.drawArc(2 * a / 5, 230, 6 * a / 5, 6 * a / 5, 360, 360); // draw small lines g.drawLine(12 * a / 5, 3 * a - 7, 18 * a / 5, 3 * a - 7); g.drawLine(2 * a / 5, a + 13, 8 * a / 5, a + 13); g.drawLine(2 * a / 5, 3 * a - 7, 8 * a / 5, 3 * a - 7); g.drawLine(12 * a / 5, a + 13, 18 * a / 5, a + 13); g.drawLine(a, 17 * a / 10, a, a / 2); g.drawLine(3 * a, 17 * a / 10, 3 * a, a / 2); g.drawLine(a, 7 * a / 2, a, 23 * a / 10); g.drawLine(3 * a, 7 * a / 2, 3 * a, 23 * a / 10); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro03_T094054 mainWindow = new cAss03Pro03_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 4: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro04_T094054 extends JFrame { // constructor public cAss03Pro04_T094054() { // set size width=400, height= 400 setSize(400, 400); // set background color setBackground(Color.white); // set title setTitle("Eight Parts"); }
// paint function public void paint(Graphics g) {
int x0 = 200, y0 = 200; int r = 50, w = 200; g.setColor(Color.WHITE); g.drawOval(x0 - r * 3 / 4, y0 - r * 3 / 4, r * 3 / 2, r * 3 / 2); g.setColor(Color.BLACK); g.drawOval(x0 - r * 2, y0 - r * 2, 4 * r, 4 * r);
g.drawLine(x0 - w / 2, y0, x0 - 3 * r / 4, y0); g.drawLine(x0 + w / 2, y0, x0 + 3 * r / 4, y0); g.drawLine(x0, y0 - w / 2, x0, y0 - 3 * r / 4); g.drawLine(x0, y0 + w / 2, x0, y0 + 3 * r / 4);
int alpha = 45; g.drawLine(x0 + w * 5 / 14, y0 - w * 5 / 14, (int) (x0 + 3 * r / 4 * Math.cos(Math.PI * alpha / 180)), (int) (y0 - 3 * r / 4 * Math.sin(Math.PI * alpha / 180)));
alpha = 135; g.drawLine(x0 - w * 5 / 14, y0 - w * 5 / 14, (int) (x0 + 3 * r / 4 * Math.cos(Math.PI * alpha / 180)), (int) (y0 - 3 * r / 4 * Math.sin(Math.PI * alpha / 180)));
alpha = 225; g.drawLine(x0 - w * 5 / 14, y0 + w * 5 / 14, (int) (x0 + 3 * r / 4 * Math.cos(Math.PI * alpha / 180)), (int) (y0 - 3 * r / 4 * Math.sin(Math.PI * alpha / 180)));
alpha = 315; g.drawLine(x0 + w * 5 / 14, y0 + w * 5 / 14, (int) (x0 + 3 * r / 4 * Math.cos(Math.PI * alpha / 180)), (int) (y0 - 3 * r / 4 * Math.sin(Math.PI * alpha / 180)));
}
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro04_T094054 mainWindow = new cAss03Pro04_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 5: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro05_T094054 extends JFrame { // constructor public cAss03Pro05_T094054() { // set size width=600, height= 300 setSize(600, 300); // set background color setBackground(Color.white); // set title setTitle("Simple Graph"); }
// paint function public void paint(Graphics g) { // draw two lines g.drawLine(50, 250, 500, 250); g.drawLine(50, 250, 50, 50); // draw four rectangles g.setColor(Color.blue); g.drawRect(70, 200, 50, 50); g.drawRect(170, 180, 50, 70); g.drawRect(270, 120, 50, 130); g.drawRect(370, 150, 50, 100); // draw four strings g.setColor(Color.black); g.drawString("120", 83, 270); g.drawString("160", 183, 270); g.drawString("300", 283, 270); g.drawString("240", 383, 270); g.drawString("Simple Bar Graph", 250, 70); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro05_T094054 mainWindow = new cAss03Pro05_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 6: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro06_T094054 extends JFrame { // constructor public cAss03Pro06_T094054() { // set size width=600, height= 600 setSize(600, 600); // set background color setBackground(Color.white); // set title setTitle("The Clock"); }
// paint function public void paint(Graphics g) { int x, y, r; x = 300; y = 300; r = 220;
// draw ovals g.drawOval(50, 50, 500, 500); g.drawOval(80, 80, 440, 440); g.drawOval(180, 180, 240, 240); // draw lines g.drawLine(300, 80, 300, 520); g.drawLine(80, 300, 520, 300); int d1, d2; double pi; pi = Math.PI; d1 = (int) (Math.cos(pi / 3) * r); d2 = (int) (Math.sin(pi / 3) * r); g.drawLine(190, 490, 410, 110); g.drawLine(190, 110, 410, 490); g.drawLine(x + d2, y - d1, x - d2, y + d1); g.drawLine(x - d2, y - d1, x + d2, y + d1);
g.setColor(Color.WHITE); g.fillOval(180, 180, 240, 240); g.setColor(Color.BLACK); g.drawOval(180, 180, 240, 240); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro06_T094054 mainWindow = new cAss03Pro06_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 7: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro07_T094054 extends JFrame { // constructor public cAss03Pro07_T094054() { // set size width=600, height= 600 setSize(600, 600); // set background color setBackground(Color.white); // set title setTitle("Come Together"); }
// paint function public void paint(Graphics g) { g.drawArc(80, 80, 450, 450, 360, 360); g.drawArc(155, 230, 300, 300, 360, 360); g.drawArc(155, 80, 300, 300, 360, 360); g.drawArc(230, 80, 150, 150, 360, 360); g.drawArc(230, 230, 150, 150, 360, 360); g.drawArc(230, 380, 150, 150, 360, 360); g.drawArc(80, 260, 90, 90, 360, 360); g.drawArc(440, 260, 90, 90, 360, 360); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro07_T094054 mainWindow = new cAss03Pro07_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 8: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro08_T094054 extends JFrame { // constructor public cAss03Pro08_T094054() { // set size width=400, height= 450 setSize(400, 450); // set background color setBackground(Color.white); // set title setTitle("I Am Computer"); }
// paint function public void paint(Graphics g) { g.fillRect(70, 50, 260, 10); g.fillRect(60, 60, 10, 10); g.fillRect(330, 60, 10, 10); g.fillRect(90, 80, 220, 10); g.fillRect(50, 70, 10, 290); g.fillRect(340, 70, 10, 290); g.fillRect(80, 90, 10, 150); g.fillRect(310, 90, 10, 150); g.fillRect(90, 240, 220, 10); g.fillRect(140, 130, 10, 20); g.fillRect(230, 130, 10, 20); g.fillRect(190, 130, 10, 40); g.fillRect(180, 170, 20, 10); g.fillRect(170, 200, 40, 10); g.fillRect(160, 190, 10, 10); g.fillRect(210, 190, 10, 10); g.fillRect(250, 300, 60, 10); g.fillRect(80, 310, 20, 10); g.fillRect(60, 360, 280, 10); g.fillRect(60, 370, 10, 40); g.fillRect(330, 370, 10, 40); g.fillRect(60, 400, 280, 10);
}
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro08_T094054 mainWindow = new cAss03Pro08_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 9: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro09_T094054 extends JFrame { // constructor public cAss03Pro09_T094054() { // set size width=600, height= 500 setSize(600, 500); // set background color setBackground(Color.WHITE); // set title setTitle("The Balancer"); }
// paint function public void paint(Graphics g) { // draw ovals g.drawOval(100, 100, 300, 300); g.drawOval(250, 100, 300, 300); // draw lines int x, y, d1, d2, r; x = 250; y = 250; r = 150; double pi; pi = Math.PI; d1 = (int) (Math.cos(pi / 3) * r); d2 = (int) (Math.sin(pi / 3) * r); g.drawLine(x + d1, y - d2, x - d1, y + d2); g.drawLine(x + d1, y - d2, x + d1 * 3, y + d2); g.drawLine(x - d1, y + d2, x + d1 * 3, y + d2); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro09_T094054 mainWindow = new cAss03Pro09_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 10: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro10_T094054 extends JFrame { // constructor public cAss03Pro10_T094054() { // set size width=600, height= 600 setSize(600, 600); // set background color setBackground(Color.white); // set title setTitle("Comes from Mars"); }
// paint function public void paint(Graphics g) { g.drawArc(50, 50, 510, 510, 360, 360); g.setColor(Color.GRAY); g.drawArc(115, 115, 380, 380, 360, 360); g.setColor(Color.BLACK); g.drawArc(272, 50, 65, 65, 360, 360); g.drawArc(272, 495, 65, 65, 360, 360); g.drawArc(50, 272, 65, 65, 360, 360); g.drawArc(495, 272, 65, 65, 360, 360); g.drawArc(150, 87, 65, 65, 360, 360); g.drawArc(390, 84, 65, 65, 360, 360); g.drawArc(272, 50, 65, 65, 360, 360); g.drawArc(78, 165, 65, 65, 360, 360); g.drawArc(79, 382, 65, 65, 360, 360); g.drawArc(155, 462, 65, 65, 360, 360); g.drawArc(466, 163, 65, 65, 360, 360); g.drawArc(395, 458, 65, 65, 360, 360); g.drawArc(466, 382, 65, 65, 360, 360); g.setColor(Color.BLACK); g.drawLine(317, 50, 317, 560); g.drawLine(293, 50, 293, 560); g.drawLine(50, 315, 560, 315); g.drawLine(50, 295, 560, 295); g.drawLine(181, 526, 448, 97); g.drawLine(163, 513, 430, 85); g.drawLine(90, 438, 532, 190); g.drawLine(78, 420, 520, 170); g.drawLine(156, 98, 435, 523); g.drawLine(175, 87, 453, 510); g.drawLine(90, 172, 532, 420); g.drawLine(80, 193, 519, 438); g.setColor(Color.WHITE); g.fillArc(263, 261, 85, 85, 360, 360); g.setColor(Color.GRAY); g.drawLine(305, 50, 305, 560); g.drawLine(170, 522, 440, 90); g.drawLine(84, 430, 526, 180); g.drawLine(50, 305, 560, 305); g.drawLine(82, 181, 526, 430); g.drawLine(165, 92, 445, 518); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro10_T094054 mainWindow = new cAss03Pro10_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class Bài 11: - Code:
-
import javax.swing.*; import java.awt.*;
/* * @author Trinh Thai Anh * T094054 */ @SuppressWarnings("serial") public class cAss03Pro11_T094054 extends JFrame { // constructor public cAss03Pro11_T094054() { // set size width=600, height= 400 setSize(600, 400); // set background color setBackground(Color.WHITE); // set title setTitle("The Balancer"); }
// paint function public void paint(Graphics g) { // //draw the first icon g.setColor(Color.BLACK); g.fillRoundRect(140, 120, 130, 130, 70, 70); g.setColor(Color.WHITE); g.fillRoundRect(150, 130, 110, 110, 70, 70); g.setColor(Color.BLACK); g.fillRoundRect(50, 150, 250, 200, 70, 70); g.setColor(Color.WHITE); g.fillRoundRect(65, 165, 220, 170, 70, 70); g.setColor(Color.BLACK); g.fillRoundRect(185, 265, 80, 30, 20, 20); g.setColor(Color.BLACK); g.fillRoundRect(210, 240, 30, 80, 20, 20); g.setColor(Color.WHITE); g.fillRoundRect(216, 250, 17, 60, 20, 20); g.setColor(Color.WHITE); g.fillRoundRect(194, 271, 60, 17, 20, 20); g.setColor(Color.BLACK); // draw the second icon g.fillArc(345, 130, 220, 220, 360, 360); g.setColor(Color.WHITE); g.fillArc(360, 145, 190, 190, 360, 360); g.setColor(Color.BLACK); g.fillRoundRect(440, 160, 30, 110, 70, 70); g.setColor(Color.BLACK); g.fillArc(437, 280, 35, 35, 360, 360); }
/** * @paramargs */ public static void main(String[] args) { // TODOAuto-generated method stub // declare the window cAss03Pro11_T094054 mainWindow = new cAss03Pro11_T094054(); // set status as closing mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE); // show the window mainWindow.setVisible(true); }// end main function
}// end class
| | | | | |
|