这是定义jlabel的文件:
package booksale;import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* <p>Title: 图书销售管理系统</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author 王康
* @version 1.0
*/public class Operate_Frame extends JFrame {
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenu jMenu2 = new JMenu();
JMenu jMenu3 = new JMenu();
JMenu jMenu4 = new JMenu();
JMenu jMenu5 = new JMenu();
BorderLayout borderLayout1 = new BorderLayout();
FlowLayout flowLayout1 = new FlowLayout();
JPanel jPanel2 = new JPanel();
GridLayout gridLayout1 = new GridLayout(7,1);
JButton rcls = new JButton();
JButton jsq = new JButton();
JButton tscx = new JButton();
JButton xsth = new JButton();
JButton rcpf = new JButton();
JPanel jPanel3 = new JPanel();
JLabel jLabel3 = new JLabel();
BorderLayout borderLayout2 = new BorderLayout();
JPanel jPanel4 = new JPanel();
GridLayout gridLayout2 = new GridLayout(2,1);
JLabel jLabel2 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel(); public Operate_Frame() {
try {
jbInit();
DisTime();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setBackground(new Color(217, 217, 223 ));
this.setFont(new java.awt.Font("Serif", 1, 15));
this.setJMenuBar(jMenuBar1);
this.setTitle("图书销售管理系统");
this.getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(flowLayout1);
jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
jLabel1.setIcon(image2);
jMenu1.setFont(new java.awt.Font("Serif", 1, 15));
jMenu1.setToolTipText("");
jMenu1.setText("日常业务 ");
// jMenu1.setArmed(true);
jMenuBar1.setOpaque(true);
jMenuBar1.setRequestFocusEnabled(true);
jMenuBar1.setToolTipText("");
jMenuBar1.setMargin(new Insets(0, 0, 1, 1));
jPanel1.setBackground(new Color(217, 217, 223));
jPanel2.setLayout(gridLayout1);
rcls.setBackground(new Color(217, 217, 223));
rcls.setActionCommand("rcls");
rcls.setHorizontalTextPosition(SwingConstants.CENTER);
rcls.setIcon(image7);
rcls.setText("日常零售");
rcls.setVerticalAlignment(SwingConstants.CENTER);
rcls.setVerticalTextPosition(SwingConstants.BOTTOM);
jsq.setBackground(new Color(217, 217, 223));
jsq.setActionCommand("jsq");
jsq.setHorizontalTextPosition(SwingConstants.CENTER);
jsq.setIcon(image9);
jsq.setText("计算器");
jsq.setVerticalTextPosition(SwingConstants.BOTTOM);
tscx.setBackground(new Color(217, 217, 223));
tscx.setActionCommand("tscx");
tscx.setHorizontalTextPosition(SwingConstants.CENTER);
tscx.setIcon(image11);
tscx.setText("图书查询");
tscx.setVerticalTextPosition(SwingConstants.BOTTOM);
xsth.setBackground(new Color(217, 217, 223));
xsth.setActionCommand("xsth");
xsth.setHorizontalTextPosition(SwingConstants.CENTER);
xsth.setIcon(image10);
xsth.setText("销售退货");
xsth.setVerticalTextPosition(SwingConstants.BOTTOM);
rcpf.setBackground(new Color(217, 217, 223));
rcpf.setVerifyInputWhenFocusTarget(true);
rcpf.setActionCommand("rcpf");
rcpf.setHorizontalAlignment(SwingConstants.CENTER);
rcpf.setHorizontalTextPosition(SwingConstants.CENTER);
rcpf.setIcon(image8);
rcpf.setText("日常批发");
rcpf.setVerticalAlignment(SwingConstants.CENTER);
rcpf.setVerticalTextPosition(SwingConstants.BOTTOM);
jPanel3.setBackground(new Color(217, 217, 223));
jPanel3.setLayout(borderLayout2);
jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
jLabel3.setHorizontalTextPosition(SwingConstants.CENTER);
jLabel3.setIcon(image12);
jPanel2.setBackground(new Color(217, 217, 223));
jPanel4.setLayout(gridLayout2);
jLabel2.setFont(new java.awt.Font("Serif", 0, 18));
jLabel2.setText(" 当前时间: ");
jPanel4.setBackground(new Color(217, 217, 223));
gridLayout2.setRows(3);
jLabel5.setText("jLabel5");
this.getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(jPanel4, null);
jPanel4.add(jLabel2, null);
jPanel4.add(jLabel5, null);
jPanel4.add(jLabel4, null);
this.getContentPane().add(jPanel2, BorderLayout.WEST);
jPanel2.add(rcls, null);
jPanel2.add(rcpf, null);
jPanel2.add(xsth, null);
jPanel2.add(tscx, null);
jPanel2.add(jsq, null);
this.getContentPane().add(jPanel3, BorderLayout.CENTER);
jPanel3.add(jLabel3, BorderLayout.EAST);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(screenSize);
this.show();
}
*********************************************************************
这是引用jlabel4 和jLabel5的文件package booksale;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import booksale.Operate_Frame;/**
* <p>Title: 图书销售管理系统</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author 王康
* @version 1.0
*/ class DisTime extends Thread{
Calendar cal = Calendar.getInstance();
String nian = Integer.toString(cal.get(Calendar.YEAR));
String yue = Integer.toString(cal.get(Calendar.MONTH));
String ri = Integer.toString(cal.get(Calendar.MONDAY));
String shi = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
String fen = Integer.toString(cal.get(Calendar.MINUTE));
String miao = Integer.toString(cal.get(Calendar.SECOND));
public void run(){
while(true){
jLabel4.setText(" " + nian + "年" + yue + "月" + ri + "日");
jLabel5.setText(" " + shi + ":"+ fen + ":"+ miao);
try{
Thread.sleep(1000);
}
catch (InterruptedException e) {
} }
}}
只有通过Operate_Frame的对象才能访问他的成员啊,
没有对象,怎么可能会有对象的成员?