Built-in Arrow Button in Java

This is a tutorial in which we will going to create a program that will have a built-in arrow button in Java. So, now let's start this tutorial! 1. Open JCreator or NetBeans and make a java program with a file name of arrowButton.java. 2. Import the following packages:
  1. import java.awt.*; //used to access the FlowLayout class
  2. import javax.swing.*; //used to access the JFrame class
  3. import javax.swing.plaf.basic.*; //used to access the BasicArrowButton class
We will use the BasicArrowButton class of the javax.swing.plaf package to have the arrow buttons. 3. Initialize your variable in your Main, variable frame for JFrame only.
  1. JFrame frame = new JFrame("Arrow Button Sample");
4. To add the built-in arrow to the frame, we will use the getContentPane.add method then instantiate the BasicArrowButton class and the position of the arrows that you want.
  1.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.NORTH));
  2.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.SOUTH));
  3.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.WEST));
  4.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.EAST));
As you have seen the code above, we have created four buttons with different position, the North, South, West, and East position, respectively. 5. Now, have the frame set to a FlowLayout as the layout manager. Lastly, set visibility, close operation of the frame, and pack the frame. Have this code below:
  1.     frame.getContentPane().setLayout(new FlowLayout());
  2.     frame.pack();
  3.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  4.     frame.setVisible(true);
Output: output Here's the full code of this tutorial:
  1. import java.awt.*; //used to access the FlowLayout class
  2. import javax.swing.*; //used to access the JFrame class
  3. import javax.swing.plaf.basic.*; //used to access the BasicArrowButton class
  4.  
  5. public class arrowButton{
  6.   public static void main(String args[]) {
  7.     JFrame frame = new JFrame("Arrow Button Sample");
  8.    
  9.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.NORTH));
  10.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.SOUTH));
  11.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.WEST));
  12.     frame.getContentPane().add(new BasicArrowButton(BasicArrowButton.EAST));
  13.    
  14.     frame.getContentPane().setLayout(new FlowLayout());
  15.     frame.pack();
  16.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.     frame.setVisible(true);
  18.   }
  19.  
  20. }
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment