Gets total sales in most cases, there will be many records in the sales list, so the speed and efficacy of the access database are very important. Now we only need to access the total sales volume of each product in the database.
The getsales () method in Table C is connected to the database and returns an array, which contains the total amount of sale of each product.
Listing C
// Get the sales totals from the database public float [] getSales (int products) {float [] arr = new float [products]; Connection con; Statement stmt; ResultSet rs; int count = 0; String sql = "select productID Amount from p_sales "; try {// load driver: class.forname (driver); // connect to the database with the url con = DRIVERMANAGER.GETCONNECTION (DBURL, DBUID, DBPWD); STMT = con.createstatement (); // Get ResultSet RS = stmt.executeQuery (SQL); while (rs.next ()) {int product = rs.Getint ("ProductID"); // Check That The ProductID Is Valid IF (Product> = 0 && Productuct) When getSales () traverses all records, it only stores new sales quantities for each product: INT product = rs.get ("productID"); arr [product] = rs.getfloat ("Amount"); PieColor object Each product on the cake pattern should be displayed in different colors. In order to achieve this, we create a PIECOLOR object (such as Table D), which contains arrays related to colors: Color Piecolorarray [] = {New Color (210, 60, 60), New Color (60, 210, 60) ...} The PIECOLOR class defines a setNewColor () method, which can increase the CurpieColor and index, and it can check that the index should not exceed the boundary range, that is, the method used is: if CurpieColor is 赋 0 0 value. More effective is that the setNewColor () is loop after each color and performs the following code under the first color: CurpieColor ; IF (CurpieColor> = PIECOLORARRAY.LENGTH) {curpiecolor = 0;} RenderingHints and Antialiasing class The Java.awt.RenderingHints class defines a lot of methods to display twoD graphics, including alpha_interpolation, jitter, and antialiasing methods. RenderingHints helps to determine how the graphic is displayed and how the graphics reaches the optimal process. In order to be smoothed, the Antialiasing method can be used to handle the cake-like graphics. AntialiaSing is a graphic smooth processing method. Its algorithm is to select a color value of a special pixel and replace the intersection of the intersection, so that the line cross is smoothed. Figure A illustrates the effect of the Antialiasing method. It can be seen that the cross-shaped lines of the cake graphics using the Antialiasing method becomes very smooth. Figure A At the same time, a renderingHints object can also be created and passed to the Graphics2D setRenderingHints () method, as shown below: RenderingHints Renderhints = New RenderingHINTS (RenderingHints.Key_antialiasing, RenderingHints.Value_antialias_on); G2D.sethints;