?? main.java
字號:
/*
* Main.java
*
* Created on 23 marzec 2007, 16:50
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package zegarek;
/**
*
* @author Basia
*/
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Okno ok = new Okno();
ok.getContentPane().setLayout(new FlowLayout());
JLabel etykieta1 = new JLabel("Zegar");
etykieta1.setVisible(true);
ok.getContentPane().add(etykieta1);
MojPanel pan1 = new MojPanel();
ok.getContentPane().add(pan1);
pan1.repaint();
}
}
class Okno extends JFrame {
//private JLabel etykieta1;
private MojPanel pan1;
Graphics g;
public Okno() {
setDefaultLookAndFeelDecorated(true);
setSize(500,400);
setTitle("Zegar");
setBackground(new Color(255,255,204));
setResizable(false);
setDefaultCloseOperation(3);
setVisible(true);
setLocationRelativeTo(null);
}
}
class MojPanel extends JPanel {
int a1x[]=new int [60];
int a1y[]=new int [60];
int a2x[]=new int [60];
int a2y[]=new int [60];
int b1x[]=new int [12];
int b1y[]=new int [12];
int b2x[]=new int [12];
int b2y[]=new int [12];
public MojPanel(){
setVisible(true);
setLayout(new FlowLayout(1));
setBackground(new Color(255,255,204));
setSize(300,300);
}
public void paintComponent(Graphics g){
int i;
super.paintComponent(g);
for (i=0; i<= 59; i++)
g.drawLine(a1x[i],a1y[i],a2x[i],a2y[i]);
for (i=0; i<= 11; i++)
{
g.drawLine(b1x[i],b1y[i],b2x[i],b2y[i]);
if ( i==0 || i==1 || i==5 || i==6 || i==7 || i==11)
{g.drawLine(b1x[i]-1,b1y[i],b2x[i]-1,b2y[i]);
g.drawLine(b1x[i]+1,b1y[i],b2x[i]+1,b2y[i]);}
else
{g.drawLine(b1x[i],b1y[i]-1,b2x[i],b2y[i]-1);
g.drawLine(b1x[i],b1y[i]+1,b2x[i],b2y[i]+1);}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -