In thisJava Tutorial we will see How To Style The Jtable By Changeing Row Height, Show Grid, Set Grid Color, Set Background, Set Foreground, Set Selection Background, Set Selection Foreground, Set Font InJava NetBeans .
Project Source Code:
jTable1.setRowHeight(40);
//jTable1.setRowHeight(1, 100);
jTable1.setShowGrid(true);
jTable1.setGridColor(Color.red);
jTable1.setBackground(Color.BLACK);
jTable1.setForeground(Color.WHITE);
jTable1.setSelectionBackground(Color.WHITE);
jTable1.setSelectionForeground(Color.BLACK);
jTable1.setFont(new Font("Comic Sans MS", Font.ITALIC, 20));
How To Create A Placeholder String Using Java NetBeans
In thisJava Tutorial we will see How To Make A JTextField With A PlaceHolder Text Using Events => jTextFieldFocusGained + jTextFieldFocusLost InJava NetBeans .
In ThisVB.NET Tutorial we will See How To Build A Tic-Tac-Toe Game With Replay And Get The Winner And Change Winning Boxes Color Using Visual Basic.Net And Visual Studio Editor .
Part 1
Part 2
Part 3
Part 4
Project Source Code:
Public Class VB_TIC_TAC_TOE
Private Sub VB_TIC_TAC_TOE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' add event to all buttons inside the panel2
For Each c As Control In Panel2.Controls
If c.GetType() = GetType(Button) Then
AddHandler c.Click, AddressOf btn_Click
End If
Next
End Sub
Dim XorO As Integer = 0
' create button event
Private Sub btn_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
' we will clear buttons text later
If btn.Text.Equals("") Then
If XorO Mod 2 = 0 Then
btn.Text = "X"
btn.ForeColor = Color.Red
Label1.Text = "[O] Turn"
getTheWinner()
Else
btn.Text = "O"
btn.ForeColor = Color.Blue
Label1.Text = "[X] Turn"
getTheWinner()
End If
XorO += 1
End If
End Sub
Dim win As Boolean = False
' create a function to get the winner
Private Sub getTheWinner()
If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button2.Text) AndAlso Button1.Text.Equals(Button3.Text) Then
win = True
winEffect(Button1, Button2, Button3)
End If
If Not Button4.Text.Equals("") AndAlso Button4.Text.Equals(Button5.Text) AndAlso Button4.Text.Equals(Button6.Text) Then
win = True
winEffect(Button4, Button5, Button6)
End If
If Not Button7.Text.Equals("") AndAlso Button7.Text.Equals(Button8.Text) AndAlso Button7.Text.Equals(Button9.Text) Then
win = True
winEffect(Button7, Button8, Button9)
End If
If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button4.Text) AndAlso Button1.Text.Equals(Button7.Text) Then
win = True
winEffect(Button1, Button4, Button7)
End If
If Not Button2.Text.Equals("") AndAlso Button2.Text.Equals(Button5.Text) AndAlso Button2.Text.Equals(Button8.Text) Then
win = True
winEffect(Button2, Button5, Button8)
End If
If Not Button3.Text.Equals("") AndAlso Button3.Text.Equals(Button6.Text) AndAlso Button3.Text.Equals(Button9.Text) Then
win = True
winEffect(Button3, Button6, Button9)
End If
If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button5.Text) AndAlso Button1.Text.Equals(Button9.Text) Then
win = True
winEffect(Button1, Button5, Button9)
End If
If Not Button3.Text.Equals("") AndAlso Button3.Text.Equals(Button5.Text) AndAlso Button3.Text.Equals(Button7.Text) Then
win = True
winEffect(Button3, Button5, Button7)
End If
' if no one win later
' 9 buttons with X or O mean 9 char = no button is empty
If allbuttonsTextLength() = 9 AndAlso win = False Then
Label1.Text = "NO Winner"
End If
End Sub
' get all buttons text length
Function allbuttonsTextLength() As Integer
Dim btnsTxtLength As Integer = 0
For Each c As Control In Panel2.Controls
If c.GetType() = GetType(Button) Then
btnsTxtLength += c.Text.Length
End If
Next
Return btnsTxtLength
End Function
' win effect function to change buttons
' background color + foreColor when one player win
Private Sub winEffect(ByVal b1 As Button, ByVal b2 As Button, ByVal b3 As Button)
b1.BackColor = Color.Red
b2.BackColor = Color.Red
b3.BackColor = Color.Red
b1.ForeColor = Color.White
b2.ForeColor = Color.White
b3.ForeColor = Color.White
Label1.Text = b1.Text + " Win"
End Sub
' new partie button
Private Sub ButtonNewPartie_Click(sender As Object, e As EventArgs) Handles ButtonNewPartie.Click
In ThisJavascript Tutorial we will See How To Make Two Images SlideShow Using translateX & translateY To Display The Next And Previous ImageInJS And Netbeans Editor .