📄 showrectangle.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ShowRectangle extends JFrame{
public int count;
public int count2;
public int count3;
public int count4;
public int count5;
public int count6;
public ShowRectangle(int c,int c2,int c3,int c4,int c5,int c6){
//public ShowRectangle(){
this.count=c;
this.count2=c2;
this.count3=c3;
this.count4=c4;
this.count5=c5;
this.count6=c6;
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JLabel("显示成绩情况",SwingConstants.CENTER),
BorderLayout.NORTH);
getContentPane().add(new showmain(count,count2,count3,
count4,count5,count6),BorderLayout.CENTER);
//getContentPane().add(new showmain(),BorderLayout.CENTER);
JPanel numpanel=new JPanel();
numpanel.setLayout(new GridLayout(0,1));
numpanel.add(new JLabel(" "));
numpanel.add(new JLabel(" "));
numpanel.add(new JLabel(" "));
numpanel.add(new JLabel(" "));
numpanel.add(new JLabel(" "));
numpanel.add(new JLabel(" "));
getContentPane().add(numpanel,BorderLayout.WEST);
}
/* public static void main(String[] args){
ShowRectangle frame=new ShowRectangle();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}*/
}
class showmain extends JPanel{
public int count;
public int count2;
public int count3;
public int count4;
public int count5;
public int count6;
public showmain(){
}
public showmain(int c,int c2,int c3,int c4,int c5,int c6){
this.count=c;
this.count2=c2;
this.count3=c3;
this.count4=c4;
this.count5=c5;
this.count6=c6;
this.setBackground(Color.pink);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
int width=getWidth()*9/10;
int height=getHeight()*8/10;
int full=10+height*3/10;
int lenght=height*7/10;
g.drawRect(28,10,width-18,height);
g.setColor(Color.blue);
g.fillRect(5+width/7,full+(10+height-full)*(25-count2)/25-2,
width/7,(10+height-full)*count2/25+2);
g.fillRect(10+width*2/7,full+(10+height-full)*(25-count3)/25-2,
width/7,(10+height-full)*count3/25+2);
g.fillRect(15+width*3/7,full+(10+height-full)*(25-count4)/25-2,
width/7,(10+height-full)*count4/25+2);
g.fillRect(20+width*4/7,full+(10+height-full)*(25-count5)/25-2,
width/7,(10+height-full)*count5/25+2);
g.fillRect(25+width*5/7,full+(10+height-full)*(25-count6)/25-2,
width/7,(10+height-full)*count6/25+2);
g.setColor(Color.cyan);
g.drawLine(28,20+height*1/5,10+width,20+height/5);
g.drawLine(28,20+height*2/5,10+width,20+height*2/5);
g.drawLine(28,20+height*3/5,10+width,20+height*3/5);
g.drawLine(28,20+height*4/5,10+width,20+height*4/5);
g.setColor(Color.blue);
g.drawString("<60",9+width/7,30+height);
g.drawString("60~70",14+width*2/7,30+height);
g.drawString("70~80",19+width*3/7,30+height);
g.drawString("80~90",24+width*4/7,30+height);
g.drawString("90~100",29+width*5/7,30+height);
g.drawString("25人",0,20);
g.drawString("20人",0,20+height/5);
g.drawString("15人",0,20+height*2/5);
g.drawString("10人",0,20+height*3/5);
g.drawString("5人",0,20+height*4/5);
g.setColor(Color.BLUE);
g.drawString(count2+"人",9+width/7,full+(10+height-full)*(25-count2)/25-4);
g.drawString(count3+"人",14+width*2/7,full+(10+height-full)*(25-count3)/25-4);
g.drawString(count4+"人",19+width*3/7,full+(10+height-full)*(25-count4)/25-4);
g.drawString(count5+"人",24+width*4/7,full+(10+height-full)*(25-count5)/25-4);
g.drawString(count6+"人",29+width*5/7,full+(10+height-full)*(25-count6)/25-4);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -