java - How do I change button labels in a grid? -


I am trying to create a game that involves dragging the skid from the slides to the square and leaving it piece. However, I am trying to do this so that the button (with the label) can be used as an exercise. Therefore, for example, a button "W" with the label should change its label to "blank" when I press the mouse over it and leave it on the other with a valid button (with another empty label). Then the second button "" (empty) should replace "W".

Using graphics in Java is completely new to me. It is enough to say, I'm not sure how to accomplish the above mentioned work here: My code is still here:

  import javax.swing. *; Import javax.swing.JButton; Import java.awt.GridLayout; Import java.awt.event. *; Class boardgame implements JFrame MouseListener {JFrame frame = new JFrame ("board game"); Jebton [] [] Bogrud; Public board game () {frame.setLayout (new grid layout (8, 8)); Bogrid = New Zebutan [8] [8]; For (Int i = 0; i & lt; 8; i ++) {for (J. J.L.; 2; J ++) {bogrid [j] [i] = New pocket (" B "); Frame.add (bogrid [ja] [i]); } For (int j = 2; j and lt; 6; j ++) {bogrid [j] [i] = new pocket (); Frame.add (bogrid [ja] [i]); } For (int j = 6; j and lt; 8; j ++) {bogrid [j] [i] = new pocket ("w"); frame.add (bogrid [ja] [i]); }} Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.pack (); Frame.Sets (405, 450); Frame.setVisible (true); } Public Zero Mouse Accelerated (MouseEver E) {} Public Zero Mouse Released (MouseEver E) {} Public Zero Mouse Butter (MouseEver E) {} Public Zero Mouse Accelerated (MouseEver E) {} Public Zero Mouse Mouse Pressed (MouseWave E) {} Class Myayation implemented the mechanism {board game bo; Mayction (board game B) {B = B; }}   

}

First of all, you will need mouse The functions released to use MouseListener to listen to the mouse and mouse means that you should definitely use the zbotone for this type of program, rather it should be a logical grid of jlbell, or images, because JebTone should react to the Exclamationist, not the mouse leftists With Rlb exceptions). I suggest using JLLL because it will be easy for them to keep the text and set them and you will have to give them lessons.

After that, you will add your mousester to your JLBEL, and press the mouse, pressed by JLable, the text mouseAvent parameter's getSource () method was pressed (and issued ) Will return to you on JLabel

Then inside your loop, you will need to add something:

  bogrid [j] [i] = new jlabel ("b"); Bogrid [j] [i] .addMouseListener (myMouseListener); frame.add (bogrid [ja] [i]);   

Where myMouseListener is your MoleListener object.


Edit
You ask in the comment:

Initial Question: One using JLABB instead of JB. A window appears that appears to be a huge empty area with a bunch of floating labels. How do I show the individual spaces as a grid with the line from the border line?

Consider providing a border with your JLable and consider giving some horizontal and vertical intervals to the grid layout.

Use a gridlighter constructor for layouts which takes 4-inch parameters, not 2, with the third and fourth parameters for horizontal and vertical intervals:

  int Gap = 4; // or whatever number looks good frame .Setlet Out (new grid layout (8, 8, difference, difference));   

For the border, consider using a lineborder that is added to the JLable in that loop, where you make it. If this limit overwhelms your text too, you can use a compound border where the internal border is a blank border with a proper bumpers and the outer boundary is a lineborder.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -