To order by word in MySQL, you need to use ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20), StudentFavouriteSubject varchar(100) ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentFirstName, StudentFavouriteSubject) values('Larry', 'Java'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentFirstName, StudentFavouriteSubject) values('Sam', 'C'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentFirstName, StudentFavouriteSubject) values('Bob', 'MongoDB'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More
A JComboBox is a subclass of JComponent class and it is a combination of a text field and a drop-down list from which the user can choose a value. A JComboBox can generate an ActionListener, ChangeListener and ItemListener interfaces when the user actions on a combo box. We can set the border to the items of a JComboBox by rendering a JComboBox which extends the DefaultListCellRenderer class and need to override the getListCellRendererComponent() method.Syntaxpublic Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)Exampleimport java.awt.*; import javax.swing.*; public class JComboBoxTest extends JFrame { public JComboBoxTest() { setTitle("JComboBox Test"); ... Read More
A JLabel is a subclass of JComponent class and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image or both text and an image. A JLabel can explicitly generate a PropertyChangeListener interface. By default, JLabel can display a text in the horizontal position and we can rotate a JLabel text by implementing the rotate() method of Graphics2D class inside the paintComponent().Syntaxpublic abstract void rotate(double theta, double x, double y)Exampleimport java.awt.*; import java.awt.geom.*; import javax.swing.*; public class RotateJLabelTest extends JFrame { public RotateJLabelTest() { setTitle("Rotate JLabel"); JLabel label ... Read More
A LinkedList is a data structure that contains a group of nodes connected in a sequential manner with a pointer. A LinkedList can behave as a dynamic array and it allocates space for each element separately in its own block of memory called a Node. Each node contains two fields, a "data" field to store an element type the list holds and a "next" field which is a pointer used to link one node to the next node.We can iterate the elements of a LinkedList in three ways in Java.Using IteratorWe can iterate the elements of a LinkedList through the Iterator class.Exampleimport java.util.*; ... Read More
This example demonstrate about How to make an Android status bar notification persist across phone rebootStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState) ; setContentView(R.layout. activity_main ) ; } }Step 4 − Add ... Read More
The local variables can be declared in methods, code blocks, constructors, etc in Java. When the program control enters the methods, code blocks, constructors, etc. then the local variables are created and when the program control leaves the methods, code blocks, constructors, etc. then the local variables are destroyed. The local variables do not have any default values in Java. This means that they can be declared and assigned a value before the variables are used for the first time, otherwise, the compiler throws an error.Examplepublic class LocalVariableTest { public void print() { int num; ... Read More
A JTextField is a subclass of JTextComponent class and it is one of the most important components that allow the user to input text value in a single-line format. A JTextField class will generate an ActionListener interface when we trying to enter some input inside it. The important methods of a JTextField class are setText(), getText(), setBorder(), setEnabled(), etc. We can add padding to a JTextField using the setMargin(Insets s) of JTextComponent class.Syntaxpublic void setMargin(Insets m)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTextfieldPaddingTest extends JFrame { private JTextField jtf; public JTextfieldPaddingTest() { jtf = new JTextField("Welcome to Tutorials Point"); ... Read More
This example demonstrates how do I change current theme at runtime in my android app.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_Black); setContentView(R.layout.activity_main); } }Step 4 − Add the following code to androidManifest.xml ... Read More
A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface.We can set the color to alternate rows of JTable by overriding the prepareRenderer() method of JTable class.Syntaxpublic Component prepareRenderer(TableCellRenderer renderer, int row, int column)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class AlternateRowColorTableTest extends JFrame { public AlternateRowColorTableTest() { setTitle("AlternateRowColorTable Test"); JTable table = new JTable(new Object[][] {{"115", "Ramesh"}, {"120", "Adithya"}, {"125", "Jai"}, {"130", "Chaitanya"}, ... Read More
Use the column-rule-width property to set the width of the rule between columns.ExampleYou can try to run the following code to implement the column-rule-width property:Live Demo .demo { column-count: 4; column-gap: 50px; column-rule-color: maroon; column-rule-style: dashed; column-rule-width: 5px; } This ... Read More