• We just launched and are currently in beta. Join us as we build and grow the community.

Built-in Arrow Button in Java

lorm76

Application Lifecycle Manager
L Rep
0
0
0
Rep
0
L Vouches
0
0
0
Vouches
0
Posts
166
Likes
27
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
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:

arrowbutton.png


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. public

    class

    arrowButton{
  5. public

    static

    void

    main(

    String

    args[

    ]

    )

    {
  6. JFrame

    frame =

    new

    JFrame

    (

    "Arrow Button Sample"

    )

    ;

  7. frame.getContentPane

    (

    )

    .add

    (

    new

    BasicArrowButton

    (

    BasicArrowButton

    .NORTH

    )

    )

    ;
  8. frame.getContentPane

    (

    )

    .add

    (

    new

    BasicArrowButton

    (

    BasicArrowButton

    .SOUTH

    )

    )

    ;
  9. frame.getContentPane

    (

    )

    .add

    (

    new

    BasicArrowButton

    (

    BasicArrowButton

    .WEST

    )

    )

    ;
  10. frame.getContentPane

    (

    )

    .add

    (

    new

    BasicArrowButton

    (

    BasicArrowButton

    .EAST

    )

    )

    ;

  11. frame.getContentPane

    (

    )

    .setLayout

    (

    new

    FlowLayout

    (

    )

    )

    ;
  12. frame.pack

    (

    )

    ;
  13. frame.setDefaultCloseOperation

    (

    JFrame

    .EXIT_ON_CLOSE

    )

    ;
  14. frame.setVisible

    (

    true

    )

    ;
  15. }

  16. }

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


Download
You must upgrade your account or reply in the thread to view hidden text.
 

449,708

322,558

322,567

Top