Adding Buttons – Java Code

Hello guys, I created this article in order to talk about how to add buttons to a Java frame and keep adding one after another.  Those new buttons also perform an action such as grouping all the button names and showing the names in the developer windows.  Developers will come to a point where they have to add more of the elements to a Java application for a purpose and perform an action that a user wants to do.  Hope this code will help you Java developers start off in performing advanced applications to better users.

 

 

As promised from the Youtube description, the code to run this application is below here:

________________________________________________________

import java.awt.Color;import java.awt.Color;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.HashMap;
import javax.swing.*; public class addbuttons implements ActionListener {private static final ActionListener addbuttons = null;public String ark;public String ara; public JButton kan;JButton[] wer;public static JFrame frame;
static ArrayList<JButton> bkk=new ArrayList<JButton>();
static ArrayList<String> bok=new ArrayList<String>();static ArrayList<Integer> bone;

public static JButton []qwe=new JButton[6];private static JButton JButton;public static int im;

static HashMap<Integer,String> hm;
public addbuttons(){ hm=new HashMap<Integer,String>(); kan=new JButton(); frame=new JFrame();frame.setTitle(“Adding Buttons”);FlowLayout lay=new FlowLayout();frame.setLayout(lay);frame.setSize(500,500);JButton butt=new JButton();butt.setText(“Look at Button”);frame.add(butt);JButton buaa=new JButton();buaa.addActionListener(e->anotherbutton());buaa.setText(“Add JButtons”);frame.add(buaa);frame.setVisible(true);

 

}
public static void main(String[]args){addbuttons tton=new addbuttons(); }
void add(){ String []arm={“one”,”two”,”three”, “four”, “five”}; for(String aa:arm){ ark+=aa.toString()+” “; } ara=ark.replace(“null”, “”); System.out.println(ara); }

static void addbuttonss(JButton[]eon){

int an=1;for(JButton cr:eon){cr=new JButton(); cr.setText(“NEW ERA Mode “+an);frame.add(cr);cr.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent g){    if(g.getActionCommand().contains(“Mode 5”)||g.getActionCommand().contains(“Mode 2”)){    //Execute when button is pressed        System.out.println(g.getActionCommand());        //System.out.println(“Print” +btnarray[i]);     } }});an++;} }

 

public static void addbuttone(JButton[]eri){bkk.add(new JButton());bkk.add(new JButton());bkk.add(new JButton());bkk.add(new JButton());bkk.add(new JButton());bkk.add(new JButton());bkk.add(new JButton());

im=0;
for(JButton sz:bkk){sz.setText(“New Loop  “+im);frame.add(sz);sz.addActionListener(e-> message(e.getActionCommand()));im++;}
int an=1; for(JButton cra:eri){ cra=new JButton(); cra.setText(“NEW ERA Mode “+an); bok.add(“New ERA Mode “+an); cra.setBackground(Color.GREEN); an++; frame.add(cra); cra.addActionListener(e -> message(e.getActionCommand())); }

 

}

public static void anotherbutton(){
bkk.add(new JButton());
bkk.get(bkk.size()-1).setText(“Button Greatly “+ im);bkk.get(bkk.size()-1).setBackground(Color.blue);
bkk.get(bkk.size()-1).addActionListener(e->message(e.getActionCommand()));frame.add(bkk.get(bkk.size()-1));frame.setVisible(true);frame.repaint();im++;}

 

 

public static void message(String dan){
 

for(JButton bu:bkk){ System.out.println(bu.getText()); } }

@Overridepublic void actionPerformed(ActionEvent ee) { System.out.println(ee.getSource());

}}

 

________________________________________________________
If you want to pay for my services for advance Java codes, click here:

https://www.fiverr.com/towcal/java-program-tuning-and-customizing?context&context_referrer=search_gigs&context_type=new&pckg_id=1&pos=1&ref_ctx_id=b41c46ec-8d96-4002-90dc-dfd241a2eff9&funnel=10272682-a650-42e0-b0bd-2ee1c9d6ba59
To become a Facebook fan, click here:

https://www.facebook.com/ExcelQualityProgramCustomize34?ref=aymt_homepage_panel

 

To check out my videos, click here:

https://www.youtube.com/channel/UCdhZjVbM-pS3sL1iqtjyDgQ

 

Multiple Worksheet Tabs!! Navigate Them Easily

With Microsoft Excel in mainstream use, it is heavily used for crunching data and other tasks.  One of the main irritations about the software is the many tabs people created to categorize their information.  Too many tabs creates the bottom portion of the screen to shorten because not too many names can be shown at once.  It is also somewhat frustrating when users such as me have to move the mouse down to the bottom screen portion just to click the arrows and scroll through the different names.

To turn that problem around, I went through the user-form version in Excel VBA for creating a navigation window dialog.  That dialog will help me to display the tab names in three empty boxes. I use arrow buttons on the dialog box to scroll through the different work tabs of a workbook and then display the names in three empty boxes of the dialog window.  Scrolling from right to left or vice-versa helps me to go through subsequent and previous tabs easily with the dialog in the middle screen and I don’t have to move my mouse way down.  I click on one of the three boxes containing the sheet name I want to go to and I will be arriving at that worksheet tab.  This process through this dialog will make it faster to copy or paste data in different tabs quickly.   

This video shows how the process is done:

After watching this video, here are the lines of codes that run my macro so you can put it for your user-form to navigate through the tabs:

 

For the first command button, these are the codes:

***************************************************

Private Sub CommandButton1_Click()

m = CommandButton1.Caption

 

If IsEmpty(m) Or m = “” Then

MsgBox “There is no sheet name in the selected box.”

Else

ThisWorkbook.Sheets(m).Select

 

End If

 

End Sub

 

***************************************************

 

For the second command button, these set:

***************************************************

Private Sub CommandButton2_Click()

 

m = CommandButton2.Caption

 

If IsEmpty(m) Or m = “” Then

MsgBox “There is no sheet name in the selected box.”

Else

ThisWorkbook.Sheets(m).Select

 

End If

End Sub

***************************************************

 

 

For the third command button, here is this set:

***************************************************

Private Sub CommandButton3_Click()

m = CommandButton3.Caption

 

If IsEmpty(m) Or m = “” Then

MsgBox “There is no sheet name in the selected box.”

Else

ThisWorkbook.Sheets(m).Select

 

End If

 

 

End Sub

***************************************************

 

 

 

For the arrow codes, here they are:

***************************************************

 

Private Sub SpinButton1_Change()

X = 1

Dim wa(1200000, 1)

 

 

 

For Each ht In ThisWorkbook.Worksheets

 

 

wa(X, 1) = ht.Name

X = X + 1

 

Next ht

 

m = SpinButton1.Value

dd = wa(3, 1)

CommandButton1.Caption = wa(m, 1)

CommandButton2.Caption = wa(m + 1, 1)

CommandButton3.Caption = wa(m + 2, 1)

 

 

Dim t As Worksheets

End Sub

***************************************************

 

 

 

For the closing command, these are the codes:

***************************************************

 

Private Sub CommandButton4_Click()

 

Unload UserForm2

Dim ht As Worksheets

End Sub

***************************************************

Hope these code sets run well on your Excel software and improve your productivity.  If you have any problems, please e-mail me or leave comments below so i can answer them. 

To connect with me on the media platform, click through these:

https://twitter.com/trickoutexcelhttps://www.facebook.com/ExcelQualityProgramCustomize34?ref=aymt_homepage_panel

https://www.facebook.com/ExcelQualityProgramCustomize34?ref=aymt_homepage_panel

To see my other videos, click here:

https://www.youtube.com/channel/UCdhZjVbM-pS3sL1iqtjyDgQ

To pay for my services so I can solve your complex Microsoft Excel issues:

go here: https://www.fiverr.com/towcal/accelerate-excel-work-through-macros-and-vba

And… to see my other articles at this site, hover here:

https://teachexceltrick.wordpress.com/

VBA Excel – Delete Blank Rows to Move Up Data

If you are like me and other Excel users who have to to clean up data after deleting contents, you must be tired of using your mouse to select blank rows and then right-click your mouse to delete them.  I have been through that situation many times when I have to polish up my workbook and structure it in a presentable format.  

It takes too long when I have to combine keyboard shortcuts or a couple of mouse of clicks in order to get rid of useless junk.  That can be tedious and easy to lose focus doing such a repetitive task after a while.  To shorten the time it takes me, I turned to VBA coding to give me extra leverage in deleting blank rows and have other cell contents move up to the nearest non-blank cell.  This kind of flexible coding through Visual Basic Access language helps me to structure my data faster and put more focus on seeing things from a bigger picture of how I want to organize content.  Cleaning up in Microsoft Excel gets to be mind-numbing.

This video shows how my macro is performed in deleting blank rows:

Some details about my macro:

Be careful in how you choose the blank rows, because once you choose a column that has in-between blanks, the first blank one will be selected as a whole row and delete the entire contents that are empty or not.  As you have seen in that video, it shows that all blank cells will be highlight as entire rows and delete them in order to move the data up and do it so on for the next blank cells.  That is why it is good to put a row number in order to stop the process at a certain point and not get rid of necessary data that you need.  So, structure the data the way you want and go through the process to get rid of redundant blank rows.

Now, for the codes that run my Blank Row macro, here are the set:

*********************************************************************

Sub del_rows()
o = 0
mm = InputBox(“Enter row number to stop.”)

Application.ScreenUpdating = “false”

h = 1

jj = Selection.Column
a = ThisWorkbook.ActiveSheet.Cells(Rows.Count, jj).End(xlUp).Row

dm = a

For d = 1 To a
pattern:
o = 1 + o

n = InStr(1, o, mm)

If InStr(1, o, mm) = 1 Then
GoTo ar

End If

If IsEmpty(Cells(d, jj)) = True Then

Rows(d).Delete
a = ThisWorkbook.ActiveSheet.Cells(Rows.Count, jj).End(xlUp).Row

h = 1 + h

If h = dm Then
GoTo aimed

End If

GoTo pattern

End If
Next d

aimed:

ar:
End Sub
*********************************************************************

If you want get a tutorial on how to delete blank cells in each column, here is the link to the other article: 

https://teachexceltrick.wordpress.com/2015/04/02/delete-multiple-blanks-for-each-column-via-excel/

To view my other articles, click here:https://teachexceltrick.wordpress.com/page/3/

Excel Hovering Copy! || No Clicks Needed!!

How is it going Excel users?  Still loving Microsoft Excel at this point and only hate it a little?  Then, keep on reading this article about a new type of copy feature that I have created via the VBA background in Excel.

After reading John Walkenbach’s book on Power Programming, I have come across a great concept called mousemove enabling a button to be activated by hovering a mouse icon over the button without clicking.  No mouse buttons have to be pressed or keyboard shortcuts activated to start this great concept.  Just move the mouse pointer over the mousemove button and any macro or process you assigned via the VBA background will initiate.  This kind of process can save users a lot of time in performing repetitive tasks just by moving the direction of the mouse onto a button.

For the project I did with this concept, I involve the copy and paste feature showing how the data can be moved across a column by hovering over a button.  A video below will show how the process works so you can follow easily how it is done.

A few instructions on how to start off: Create a few columns of list. After you create your lists, use the selection box to go into the first row of any column in order to test the macro feature.  You can leave some gaps between the lists if you only want to copy a few list to be copied and pasted into a consolidation of one list.  After you performed your initial setup, follow the video in how the macro is done and performed your own test in Excel.

For the code lines that run the Single Copy function, here is the set:

****************************************************************************************

Private Sub CommandButton1_Click()

End Sub

Private Sub commandbutton1_mousemove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

MsgBox (“Please move mouse away from button now.” + vbNewLine + “Press Esc key to close box.”)

restart:
h = ThisWorkbook.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

If h = 1 Then
h = 0
End If

jk = Selection.Column
jj = Selection.Row

ky = ThisWorkbook.ActiveSheet.Cells(Rows.Count, jk).End(xlUp).Row

For Z = 1 To ky
h = h + 1
Cells(h, 1) = Cells(Z, jk)

Next Z

done:
End Sub

****************************************************************************************

For the code commands that run my Continuous Copy function, here is the pack:

****************************************************************************************

Private Sub CommandButton2_Click()

End Sub

Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

MsgBox (“Please move the mouse away from the button now.” + vbNewLine + “Press ESC key to close the box.”)
restart:
h = ThisWorkbook.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

If h = 1 Then
h = 0
End If

jk = Selection.Column
jj = Selection.Row

ky = ThisWorkbook.ActiveSheet.Cells(Rows.Count, jk).End(xlUp).Row

For Z = 1 To ky
h = h + 1
Cells(h, 1) = Cells(Z, jk)

Next Z

jk = Selection.Column
Cells(jj, jk + 1).Select

l = Cells(jj, jk + 1)

If IsEmpty(l) = False Then
GoTo restart
Else
GoTo done

End If

done:

End Sub

****************************************************************************************

For videos on other macros of mine, here is the link:

https://www.youtube.com/channel/UCdhZjVbM-pS3sL1iqtjyDgQ

For other articles on my site, press this link:

https://teachexceltrick.wordpress.com

To pay for my services for receiving customized macros, click on this link under Towcal:

https://www.fiverr.com/towcal/accelerate-excel-work-through-macros-and-vba

Come back to this website for unique macros to make your Microsoft Excel a Power House!

Numbers a Mixed-Up Mess in Microsoft Excel? Sort This Way!

 

Getting tired of the agony in dealing with unsorted numbers and spending minutes in sorting them when you have other tasks to complete?  I understand your issue and through the awesome power of VBA, I created a macro to solve that problem and have it tallied up in a list as a solution.  It is a great tool that can probably save you hours in sorting them in order and have it done in a minute or so.

 

Click on this video to see how it is done-

 

 

Some notes on how to carry out the macro accurately:

So, make a list of the numbers from the lowest to the highest.  You can begin the numbers from anywhere and it doesn’t have to begin with 1.  You can also end the number with any high number that you wish to put in to complete the list.

After you come up with the numbers, put the list at L1 and then move the selection box to L1 to begin the sorting and counting process.  Then, click the macro and the rest will fall through if you followed these directions carefully.

 

This macro can you save you a lot of time when it comes to sorting and counting numbers when you have a scattered matrix to deal with.  So let me know how the macro helped you by commenting below and commenting on the Youtube video you have just seen.

 

Also, here are the codes that run my macro so you can have your own version:

********************************************************
Sub number_ordering()
Dim cell As Range
yu = 1

k = 1

j = Selection.Column

Cells(1, 1).Select

x = 1

Selection.CurrentRegion.Select

re:
h = Cells(x, j)
For Each cell In Selection
If cell = h Then
k = ThisWorkbook.ActiveSheet.Cells(Rows.Count, j + 7).End(xlUp).Row
Cells(k + 1, j + 7) = h
End If

Next cell

x = x + 1

h = Cells(x, j)

If IsEmpty(h) = False Then
GoTo re
Else
GoTo fin

End If
fin:
With Cells(k + 1, j + 7)
.Select
End With

k = Selection.Column
Cells(1, k).Delete
Selection.CurrentRegion.Select

x = 1
recount:
h = Cells(x, j)

Dim jj As Range
For Each jj In Selection

If h = jj Then
l = l + 1
End If

Next jj
b = Selection.Column
Cells(yu, j + 1) = l
Cells(yu, j + 1).Font.Bold = “True”
x = x + 1
h = Cells(x, j)
yu = 1 + yu
l = 0
If IsEmpty(h) = “False” Then
GoTo recount
Else
GoTo done

End If

done:
End Sub

********************************************************

 

 

 

To see my other tutorial articles on this site, click here–

https://teachexceltrick.wordpress.com/

 

To pay for my services in order to get advance macros for your complex issues, click here–

https://www.fiverr.com/towcal/accelerate-excel-work-through-macros-and-vba

 

To see my other Youtube videos, click here–

https://www.youtube.com/channel/UCdhZjVbM-pS3sL1iqtjyDgQ

 

Come back to this site for future articles.

 

Search Text and Build Hyperlinks – Excel VBA

Hey Excel users, are you tired of using the find feature in Microsoft Excel in order to search a text but are sick and tired of not getting an automatic link to click on in order to get to that search result?

Well, I am.  I get tired of squinting my eyes to read tiny search results and then clicking one result at a time just to find that particular text.  I want to read text in large size and then have a set of hyperlinks to click on so Excel can take me to that text.  I also want the hit search to display the results corresponding to what I put in the search box to get a better idea of the type of information I am looking for.

 

So, I made my own find feature in Excel by using VBA in the background to search for text in a column and input in the box what I want.  Then a list of hit results are built up in the form of hyperlinks to get a preview of what the sample results look like before I click on that cell.  Getting a preview of them before I click on that hyperlink gives me a greater precision in the type of information I am looking for.

 

Here is a video tutorial on how my own find feature works in a straightforward way of finding text.

 

 

For the VBA codes that run my “Search and Hyperlink” feature, here they are:

***********************************************************************

 

Sub searchandlinkup()
v = 1

candidatelook = InputBox(“Enter the Text You Want To Search”)

rw = ThisWorkbook.ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

ab = selection.Column
cr = ThisWorkbook.ActiveSheet.Cells(Rows.Count, ab).End(xlUp).Row

For dr = 1 To cr
Z = Cells(dr, ab)
L = InStr(1, Z, candidatelook)

If L > 0 Then
With Cells(dr, ab)
.Select
.Font.Bold = “True”
End With

n = Cells(dr, ab)

h = ActiveSheet.Name

kk = selection.Row

ActiveSheet.Hyperlinks.Add _
anchor:=Cells(v, rw + 5), _
Address:=””, _
SubAddress:=”‘” & h & “‘” & “!” & “C” & kk, _
TextToDisplay:=n

v = v + 1

End If
Next dr

Cells(1, rw + 5).Select

End Sub

***********************************************************************

 

For the VBA codes that run my “Go To” Destination feature after you select a hyperlink, these are the set:

***********************************************************************

Sub goback()

p = InputBox(“Enter the Column Letter You Clicked the Hyperlink on”)

gb = selection.Column
fd = selection.Row

Cells(fd, gb).Hyperlinks(1).Follow

k = Cells(fd, gb)

h = selection.Row

md = ActiveSheet.Cells(h, Columns.Count).End(xlToLeft).Column

Y = Cells(fd, gb)

b = ActiveSheet.Name

md = 1 + md

fd = fd

ActiveSheet.Hyperlinks.Add _
anchor:=Cells(h, md), _
Address:=””, _
SubAddress:=”‘” & b & “‘” & “!” & p & fd, _
TextToDisplay:=”Go Back To ” & k

End Sub

***********************************************************************

 

To get video tutorials on my other projects, click on this link:

https://www.youtube.com/channel/UCdhZjVbM-pS3sL1iqtjyDgQ/feed.

 

To get your own custom macros made particularly for you, click on this link:

https://www.fiverr.com/towcal/accelerate-excel-work-through-macros-and-vba.

 

Thanks for reading guys and come back to my website for more future articles.