Results 1 to 4 of 4
Thread: JLabel-
Hybrid View
-
1st September 2009 22:19 #1
JLabel-
, . Java, , , - newbie .
JLabel-, LayeredPane. 4 , - 4 . MouseEvent-, ( .getX .getY ).
, , ( , ) , - .setText() NullPointerException. label[12].setText("myLabel"); , .
GUI-, . - - , .
Code:import javax.swing.*; import java.awt.*; import java.sql.*; import java.security.*; import java.util.*; import java.lang.*; public class SpecRework implements MouseListener //implements MouseMotionListener { JFrame frame; JLayeredPane layeredPane; JLabel bgrLabel, testLabel; JLabel[] tp, tn, tk, tz; public SpecRework() //throws SQLException, ClassNotFoundException { frame = new JFrame("Spec"); frame.setPreferredSize(new Dimension(436, 650)); frame.setResizable(false); frame.setLayout(null); layeredPane = new JLayeredPane(); layeredPane.setBounds(0, 0, 430, 590); frame.getContentPane().add(layeredPane); frame.pack(); frame.setVisible(true); JLabel[] tp = new JLabel [21]; JLabel[] tn = new JLabel [21]; JLabel[] tk = new JLabel [21]; JLabel[] tz = new JLabel [21]; ... int nXP = 51; int nYP = 64; int nXS = 290; // next on 342 int nYS = 25; for (int i=0; i<21; i++) { tn[i] = new JLabel(""); tn[i].setBounds(nXP, nYP, nXS, nYS); //tn[i].addMouseListener(this); layeredPane.add(tn[i], new Integer(20)); nYP = nYP + 25; } ... tp[12].setText("12"); // testLabel = new JLabel(); testLabel.setBounds(60, 150, nXS, nYS); layeredPane.add(testLabel, new Integer(30)); testLabel.addMouseListener(this); } .... public void mousePressed(MouseEvent e) { //eventOutput(e); testLabel.setText("Work!"); // , testLabel tn[13].setText("Work!"); // NullPointerException } .... public static void main(String args[]) throws SQLException, ClassNotFoundException { SpecRework window1 = new SpecRework(); } }P67 Extreme4 | i5-2500K /45x100/ + HDT S1283 | 2x4GB KHX21C11T3K2 /2133 11-12-11-30-1T/ | GTX570 TFIII PE/OC | WD3000HLHX, WD6402AAEX | Silent Pro M600 | Cosmos RC-1000 | SM2053BW
UT X48-T3RS | E5200 /333x9/ | 2x1GB Trident /1333 6-6-6-18-2T tRD7/ | HD5770 | ... | FSP 400PNF
6730s
-
1st September 2009 23:14 #2Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
, NullPointerException.
, .
-
1st September 2009 23:49 #3
Last edited by System.gc(); 2nd September 2009 at 00:47.
UD3R|Q9550+1283|4x2 G.Skill@1066|MX500+1002FAEX+640AAKS+ST31 60|RX580-8GB|1841BLT|SS-760XP|Define7|z24i|Edifier S350DB
geniusloci: ) ; ) ; ) ?
nope|r.i.p.
-
2nd September 2009 00:16 #4
, , , this . this super .

.. , , . , , ( )
!Last edited by Palikarov; 2nd September 2009 at 00:55.
P67 Extreme4 | i5-2500K /45x100/ + HDT S1283 | 2x4GB KHX21C11T3K2 /2133 11-12-11-30-1T/ | GTX570 TFIII PE/OC | WD3000HLHX, WD6402AAEX | Silent Pro M600 | Cosmos RC-1000 | SM2053BW
UT X48-T3RS | E5200 /333x9/ | 2x1GB Trident /1333 6-6-6-18-2T tRD7/ | HD5770 | ... | FSP 400PNF
6730s




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in