This Java Pie Chart example is going to show you how to draw Pie Charts in Java. This Java Pie Chart example is drawing a pie chart to show the percentage of marks obtained in particular session. In this example we have used the object of JFrame class that calls the PieChartPanel class. The Font class represents the font 'Book Antiqua'. The method getPercentInstance() of NumberFormat class returns the percentage format for the current default locale. The ComponenetAdapter class is an abstract adapter class which is called to receive the component events. The BufferedImage class is called by image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) which defines the image of pie chart The method Math.min(width,height) returns the smaller of two into values. The Ellipse2D.Double class is called to draw the circle shape. Following code draws the leading edge of pie: g2.draw(new Line2D.Double(cp, cq, p, q)) The angle is defined by: phi = (marks[j]/total) * 2 * Math.PI...
In this section, you will learn how to set an icon for the frame in Java Swing. This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon situated on the title bar is seen on the taskbar also. For this purposes, various methods as follows has been used: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); Above method sets the icon for the frame or window after getting the image using the Image class method named getImage(). frame.getDefaultToolkit(): This is the method of the Toolkit class which gets the default toolkit. Here is the code of program: import javax.swing.*; import java.awt.*; public class SettingIconFrame{ public static void main(String[] args){ JFrame frame = new JFrame("Setting an Icon for a frame"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.se...
Swing supports data transfer through drag and drop, copy-paste, cut-paste etc. Data transfer works between Swing components within an application and between Java and native applications. The ability of data transfer is beneficial to programs between Java applications, between components etc. There are two ways to transfer data. These are: 1. The diagram below displays the Drag and drop (DnD) functionality of Swing. 2. The diagram below displays the cut/copy and paste functionality of Swing. That is the clipboard transfer via cut/copy and paste. The path of the data is shown by the arrows. To be more precise, first of all the bundling of data takes place into a package known as Transferable to begin Data Transfer. Then the data gets extracted by an object i.e. TransferHandler from the Transferable which is provided by the component.
Comments