Java Reference
In-Depth Information
File: its/ResizeDisplay/ResizeFrame.java
package its.ResizeDisplay;
1.
2.
3.
import its.SimpleFrame.SimpleFrame;
4.
5.
public class ResizeFrame extends SimpleFrame{
6.
7.
public ResizeFrame(){
8.
ResizePanel rp = new ResizePanel();
9.
this. setSize(500,300);
10.
11.
this. getContentPane().add(rp);
12.
13.
}
14.
15.
}
File: its/ResizeDisplay/ResizePanel.java
package its.ResizeDisplay;
1.
2.
3.
import java.awt.Color;
4.
import java.awt.Graphics;
5.
import javax.swing.JPanel;
6.
7.
public class ResizePanel extends JPanel{
8.
9.
public ResizePanel(){
10.
this. setBackground(Color.yellow);
11.
}
12.
13.
public void paintComponent(Graphics g)
14.
{
15.
super. paintComponent(g);
16.
// get the current dimensions of the panel
int currentWidth = this .getWidth();
17.
int currentHeight = this .getHeight();
18.
19.
20.
// take a third of the current dimensions
int wThird = currentWidth/3;
21.
int hThird = currentHeight/3;
22.
// set color to black
23.
Search WWH ::




Custom Search