⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 Clock source code in Java
💻 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);}
    }
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -