Connect with us

Java Programming

Java Swing CheckBox Tutorial Using NetBeans

Published

on

In this tutorial, you will learn to use Java Swing checkboxes using Netbeans IDE. This java application will show some food items along with their prices. The user is asked to select the food items to buy. On selecting the food items, the bill amount for the selected food items will be displayed as shown in the figure below:

figure 1

I am using NetBeans IDE to build a Java application. To create this application, follow the steps below:

  1. Launch Netbeans, choose File->New Project option.
  2. The Choose Project dialog box will open. Because, we want to create a Java desktop application, select the “Java” option from the Category pane and the “Java Application” option from the Projects pane. Select the Next button to proceed. The next dialog box will ask the name of the Java application and the location on the drive where we want to create the application. Let us name this Java application as “checkBoxDemoApp” and let the location be the default location as shown in the figure below.

Figure 2

  1. Click on Finish button to create the application. The NetBeans IDE will automatically create a Java class file for you named CheckBoxDemoApp.java with some default code. The project window will appear as shown below:

Figure 3

To create the GUI (Graphical User Interface), we will be using the Java Swing Toolkit. To work with the Java Swing Toolkit, you need to add a JFrame form to the application. So, right click the package, checkbox DemoApp in the Source Package node in the Project window and choose New->JFrame Form option from the context menu that pops up. You will be asked to specify the class name for the new JFrame form. Let’s enter fastfood as the class name. Click the Finish button to create the JFrame form, keeping the rest of the text boxes in the dialog box at their default values.

Figure 4

A Java class file, the FastFood.java file, will be added to the project along with some default code. The Project window will now appear as shown below:

Figure 5

Additionally, an empty JFrame form will be created and opened in the editor window with a toolbar containing several buttons. We’ll be working primarily with the following two toolbar buttons:

  • design – This button will enable us to work with GUI components. We can drag GUI components from the palette window and drop them onto the form
  • Source – This button will show the source code of the class. We can write, edit, debug code etc. Java code for any component. in this mode
See also  Understanding Textiles - Delve Into the World of Artisan Batiks

In this application, we will need two Label components and three Check Box components. The three check box components will display the three food items along with their price. One of the two label components will be used to display the title and the other label component will be used to display the bill amount of the selected food items.

Select the JFrame form i.e. FastFood.java file from the Project window and then select the Design toolbar button from the Editor tab. While in design mode, drag a Label component from the Swing Control category of the Palette window and drop it onto the JFrame form. Repeat the process for the second label component. Similarly, drag a check box component from the Swing control category and drop it onto the JFrame form. Repeat the process for two more check boxes as we want three check box components in this application. To increase the visibility of these GUI components, we need to increase their font size. So, select all the five components i.e. Ctrl+click on each component on the JFrame form and select the Font property from the properties window. Select the desired font and size as shown in the image below:

Figure 6

After increasing the font size, display the five components as shown in the figure below:

Figure 7

The next step is to change the text of these components. You can change the text of any component in the following two ways:

  • Right click on the component on the JFrame form and select Edit Text option from the context menu that pops up. You can overwrite the text of a component by pressing the Enter key
  • Click on Component on the JFrame Form and select the Text property from the Properties window. Type the desired substance in the component’s Text property.

Using any of the above methods, let’s change the text property of the components as below:

  • Set the text of the first label component to “Select Foods”.
  • Set the text of the first check box to “Burger $5”.
  • Set the text of the second check box to “Hot Dog $7”.
  • Set the text of the third check box to “Pizza $10”
  • Remove the Text property of the second Label component as its Text property will be set via Java code. Through this label component we will display the total bill amount of the selected food items.
See also  A Comparison Between The Java IDEs: Netbeans and Eclipse

After setting the Text property of all five components, the JFrame form will appear as shown below:

figure 8

Every Java Swing component that we drop on a JFrame form is given a default variable name such as jLabel1, jLabel2, jCheckBox1, jCheckBox2 and so on. We need to assign meaningful variable names to these components. To assign a variable name to any component, simply right click on it and choose Change Variable Name option from the context menu that opens. Let’s set the variable name of the first check box to jCheckBoxBurger, the second check box to jCheckBoxHotDog and the third check box to jCheckBoxPizza. Also, set the second Label component’s variable name to jLabelResponse.

We want that whenever a checkbox is checked or unchecked, the bill amount of the selected checkbox will be displayed.

write code

Currently, we are in design mode and in order to write the code, we need to switch to source mode. To switch to source mode, either you click on the Source toolbar button from the editor window or double click on any Java Swing component in the JFrame form. On double clicking on the component, you will be taken to source mode to write the code for that component. We’ll start writing the code for the jCheckBoxBurger component. So, double click on jCheckBoxBurger and you will be taken to source mode. Write the following code:

int billAmount = 0;

private void jCheckBoxBurgerActionPerformed(java.awt.event.ActionEvent evt) {

if (jCheckBoxBurger.isSelected()) {

BillAmount=BillAmount+5;

} Otherwise {

BillAmount=BillAmount-5;

,

jLabelResponse.setText(“BillAmount$” + String.valueOf(billAmount));

,

Description of above code

You define a global integer variable called BillAmount and initialize it to 0. The jCheckBoxBurgerActionPerformed method will be invoked when some action is performed on the jCheckBoxBurger i.e. whenever it is checked or unchecked. In the jCheckBoxBurgerActionPerformed method, we determine whether the checkbox is checked or not. If the checkbox is checked, the integer value 5 is added to the BillAmount variable. If the check box is unchecked, a value of 5 is subtracted from the BillAmount variable.

See also  Difference Between JSF, Servlet And JSP

After writing the code for jCheckBoxBurger, we need to write the code for jCheckBoxHotDog. So, from Code Mode, we will go back to Design Mode by clicking on the Design Toolbar button from the Editor window. From design mode, double click on jCheckBoxHotDog and in code mode write the following code in the automatically created jCheckBoxHotDogActionPerformed method:

private void jCheckBoxHotDogActionPerformed(java.awt.event.ActionEvent evt) {

if (jCheckBoxHotDog.isSelected()) {

BillAmount=BillAmount+7;

} Otherwise {

BillAmount=BillAmount-7;

,

jLabelResponse.setText(“BillAmount$” + String.valueOf(billAmount));

,

Again, return to Design Mode by clicking the Design Toolbar button. Double click on jCheckBoxPizza and type the following code in code mode:

private void jCheckBoxPizzaActionPerformed(java.awt.event.ActionEvent evt) {

if (jCheckBoxPizza.isSelected()) {

BillAmount=BillAmount+10;

} Otherwise {

BillAmount=BillAmount-10;

,

jLabelResponse.setText(“BillAmount is $” + String.valueOf(BillAmount));

,

After writing the code for all three check boxes, our project is ready to run. You can run the project by choosing one of the following three options:

  • Selecting the Run Project Toolbar button from the toolbar at the top
  • press the F6 key
  • Select Run->Run Project option from the menu bar

If you run the project now, you will not get any output because at this time the main class of the project is CheckBoxDemoApp.java and we have not written any code in this java file. So, we first need to replace the main class file. So, right click on the checkboxDemoApp project in the project window and choose Properties option from the context menu that pops up. From the Properties dialog, select the Run category from the Categories pane. In the Main class textbox, you will find the text, CheckboxDemoApp.CheckboxDemoApp which confirms that when running the project, the CheckBoxDemoApp.java file will be executed first. Change the content in Main class textbox to CheckboxDemoApp. To indicate that you want to run the fastfood.java file first whenever the project is run as shown in the figure below

Figure 9

Now you are ready to run the project. Upon running the project, you will get the following three food items to choose from as check boxes. Select any food item and you get their bill amount:

Figure 10

You can download the complete project from the following link: http://bmharwani.com/checkBoxDemoApp.zip

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published.

Java Programming

Candi Rejo Village – Community Based Tourism Project in Central Java

Published

on

By

Earlier this year my husband and I experienced real rural life in Central Java. We went to a village called Kandy Rejo. It is located about half an hour away from Borobudur, the largest Buddhist temple in Indonesia.

We have heard from our partners in Indonesia that Kandy Rejo has launched a community-based and eco-tourism project. We went on to learn more about this project. In our perspective, community based tourism means tourism that advises, engages and benefits the local community. We wanted to see if this was really the case in this village.

At first, we weren’t really sure what to expect. We bought our tickets from Bali, made arrangements with the village head, and next thing we know we were at the airport in Jogjakarta.

Our guide was called IJ (pronounced EE-J). She was very friendly and talkative, although her English was limited. She was an interesting woman. She is about 35 years old, and she wears a hijab (head scarf) and long-sleeved shirt everyday, even when the weather is very hot. Obviously this is a normal look for Muslim women out there. IJ is a single mom who has raised 2 kids herself. She is the only female guide in her village and she is very proud of it. She said she cultivates like the rest of her village when there are no visitors to guide her around.

After meeting IJ we left for the city, which is about 1 hour drive from the airport. The view was amazing. As we passed through mustard fields, corn fields, tapioca fields and other types of vegetable farms, we could see the volcano in the distance. We also passed a 9th century Buddhist temple called Pawan. It is dedicated to Kuvera, the god of fortune.

See also  Candi Rejo Village - Community Based Tourism Project in Central Java

When we reached Kandy Rejo, the first thing we did was meet the village head. We thought he would be this old man with a gray mustache, like many other Indonesian government officials. We were surprised when the village head Mr. Ian, appeared. A charming 28 year old man, soft spoken and well dressed.

He briefly explained the history of eco-tourism in Candi Rejo. A few years back an Indonesian NGO approached the village and introduced the concept of community based ecotourism. The idea was adopted by the community in Candi Rejo, after several village meetings. The village also has the advantage of being very close to Borobudur, the largest Buddhist temple in Indonesia and a great wonder of the ancient world. They have a river that can be used for white water rafting, and also a nice path called Vaatu Kendil, which is the way to Kendall Hill. The 5 Jwalamukhi and the complete construction of Borobudur temple can also be seen from the top of this hill.

The ecotourism project in Candi Rejo is a pilot project in Indonesia. About 5,000 people live in the village, and most of the people there are farmers. The main entity that manages the tourism industry in Kandy Rejo is not the government, but the cooperative community. The head of the cooperative still reports to the village head, but the revenue goes directly to the local people.

The local people voluntarily joined the cooperative. For example, those who have extra rooms in their homes can sign up as an accommodation provider. People who have horse-drawn rickshaws can join the cooperative society as one of the rural transport providers. Everyone in the cooperative has to agree to a roster system, which gives guides, porters, village tours, trek trail maintenance, and handicraft sales equal opportunities to make money.

See also  10 Top Tools For Java Application Developers

There is no doubt that the ecotourism project has boosted the economy of the village. Since Kandy Rejo received its official “Tourism Village” status in 2003, it has developed into a clean and prosperous village. The village headman has ordered every household in the village to grow a tropical fruit tree “Rambutan” in front of their houses. As a result, this village is becoming very green and shady. The weather in Central Java can be very hot, so these large trees can protect pedestrians from the scorching sun.

When we asked the village head if he was concerned that the tourism industry would one day bring degrading pollution to the village, he said the cooperative limits the number of visitors per year. The tourism programs they have developed also mainly focus on green tourism, not tourism programs. So naturally, most visitors to Candi Rejo are green-minded travelers. They want to learn about agriculture or experience real Javanese rural life.

In 2007, the village saw approximately 800–900 visitors. We saw pictures of his previous visitors. Some schools in Indonesia’s big cities send students to Kandy Rejo to learn about farming and rural life. It is true that many Indonesian children who grew up in a big city do not know what the trees and fruits they eat look like in the ground. This type of learning program teaches them where the food in the market came from. It also raises awareness among the students about how important it is to maintain your environment.

Candi Rejo is not only attended by students from all over Indonesia. The governments of other villages in Indonesia also visit Kandy Rejo to learn about rural tourism and ecotourism.

See also  Understanding Textiles - Delve Into the World of Artisan Batiks

We can’t forget how nice the people are at Candy Rejo. Everyone was so friendly and friendly. We felt that the community based tourism really suited their characters. His natural eagerness to accommodate his guests is what made our trip so smooth and memorable.

In Kandy Rejo we learned to play the Javanese gamelan (their traditional musical instrument). We even played volleyball with the locals, which was great fun! We took horse rickshaw everywhere during our stay (definitely 0 emissions). We were also invited to visit the village head’s house for a community meeting. It is as if we have gone there to meet our family.

We left Kandy Rejo with fond memories of this village. We’ll go back in a heartbeat. Hopefully next time we will be able to take our passengers there with us. We are proud that the eco-tourism and community-based tourism movement is rapidly developing in Indonesia. We hope that these projects can reduce poverty, create more employment opportunities and most importantly sustain Indonesia’s ecology.

Continue Reading

Java Programming

7 Skills To Look For Before Choosing An Android App Developer

Published

on

By

Android continues to dominate the mobile app market globally, which now accounts for more than 80 percent of it. More than 80 percent of smartphone users worldwide prefer to use Android mobiles and devices over other operating systems such as iOS and Windows. Google Play Store is now staggering with over 3 million applications, now serving the users in various ways. However, with such a huge number of applications already on the Android App Store, it is imperative for Android developers to create highly competitive applications to stay ahead of the competition. It’s not just an app idea that just might work, a android app developer One must possess all the necessary skills and abilities to end up with a successful and high performing application every time with unique business requirements.

Today, creating highly engaging and user-driven Android applications requires an in-depth knowledge and understanding of various programming languages, tools, and techniques. In fact, designing the application keeping in mind the fragmentation of the Android Market and the different Android devices and screen sizes is also essential to provide a smooth and uniform user experience across all devices and screens.

And all these aspects make it necessary to choose one android app developer Possess all required skills and abilities.

Now, Here Are The Skills You Should Look For Before Choosing android application developer for your next project.

Knowledge and understanding of Java and Kotlin:

Both Java and Kotlin are two essential programming languages ​​for Android application development. And your developer should be comfortable using both depending on your project requirements. The developer should be able to use the latest versions of both Java and Kotlin and should know the syntax of both. This is the first most important skill that you need to look for while choosing your Android application developer.

See also  Candi Rejo Village - Community Based Tourism Project in Central Java

Understanding XML:

XML was introduced as the standard way to encode data for Android applications. It is a structured markup language that shares many similar features with HTML such as angled brackets, tag types, deep nesting of elements, and a few more. Having a deep understanding and knowledge of XML can help developers to do app layout and coding proficiency to create quality code. And this makes it necessary to look for a developer who has expertise in using XML to create app layouts.

Practical experience of using Android SDK:

The Android Software Development Kit or SDK is a complete toolkit that developers should be aware of. From designing to developing, testing, debugging and deploying an application, this toolkit has tools for everyone. Android SDK also has libraries like Gradle which also ensure seamless application development. And the developer you are choosing for your project should know how to use and plug in this complete kit for better, efficient, lossless and faster application development.

Familiarity with Android Studio:

Android Studio is one of the essential tools in Android application developer’s toolkit and is a full-featured integrated development IDE that provides features like automatic code completion, autocomplete suggestions, easy code debugging, and more, which together help developers Help you write code easily and build high performing applications. Choosing a developer who is expert in using Android Studio is a must today.

Knowledge of API:

As an Android application developer, you may want to know about some other user-driven features like calendar accessing etc. However, look for developers associated with leading Android application development companies that offer APIs and show you how to use APIs and queries in a secure way. Having knowledge of how to use APIs makes it easier for developers to connect to APIs from Android applications. Choosing a developer with this specialized skill can ensure easy implementation and adding features to your app such as easy discovery of local locations, monitoring users’ locations, including reference maps in apps, and more.

See also  Do Interfaces Really Inherit the Object Class (the Cosmic Superclass) In Java?

Specialization in Database Management:

If you have a large amount of data in your application it can be more difficult to manage those data and databases to maintain the data. Cloud services like Parse and Firebase provide simple APIs for storing this data in the cloud, making it equally readily available on all Android devices. Developers must also know how to sync data between the remote database and local storage to enforce offline availability of the application, which allows users to use the app to some extent even when there is no internet connection. gives. This is a great way to increase customer engagement. So, check out this skill before choosing your developer for your Android project.

Knowledge of Material Design:

In these recent years, Android has introduced a new set of modern interface design standards and guidelines known as Material Design. And these guidelines include tips like how to layer various design elements on the app screen and then use styles like drop shadows, etc. And now it has become a necessity for app developers to consider and compulsorily follow these guidelines for designing Android application interfaces.

to have a deep knowledge of all these android app development Skills can help developers execute the entire application development process efficiently and ensure bug-free, well-designed, personalized, secure and ROI-driven applications. Staying ahead of your competitors on Google App Store is not easy today and that makes it extremely important to have your project prepared by an expert in Android Application Development who has all the skills shared above in this article.

Continue Reading

Java Programming

Best Programming Language for Site Design

Published

on

By

Server Server is actually responsible for providing web pages based on the needs and demands of clients on the Internet, which can be done both statically (as well as dynamically).

Server-Side Scripting Today, in web programming, most companies and designers work in this area. Server-side programming has a major difference with user’s programming, which is behind the scenes on server-side programming and a focus on databases and site communication with databases, but with simultaneous programming… meanwhile, asp. NET, Python, C#, Java languages ​​are among this type of programming, and at the top of these languages ​​is the powerful PHP language.

User-Programming In this section, web designers (page designers) dominate this domain, which is almost the opposite of user-side programming, this section focuses on visual factors. The most popular languages, HTML and CSS, we will discuss these languages ​​in the rest of this article. Simply put, with HTML the structure and organization of the site’s pages and its descriptions, such as post type, fonts, colors, and like attributes are defined by CSS; In other words, HTML creates the page and then CSS is mounted on it and sets up more details. Another case we can mention is that Java Script language functions like keystroke response or mouse control and interactive display of website are used by Java Script. This language is run only by the browser.

Server-side and User-side mechanisms:

  • The user initially opens his browser.
  • Then he starts searching search engines or enters the address of the site. For example, ArvinKaren.Com enters your browser.
  • The user section (client) forwards this request to the server in order to allow users to access the pages of the site.
  • The server verifies the request to the client segment and responds to the same user segment.
  • The client receives and translates the source or source page.
See also  Understanding Textiles - Delve Into the World of Artisan Batiks

Server Side Usage and Functions

  • Processes user input.
  • show requested page
  • web program architecture
  • Interacting with Servers and Storage Spaces
  • interact with database
  • Data encoding in HTML
  • Perform operations such as clearing, clearing in the database.

server-side programming languages

  • PHP
  • asp.net
  • c++
  • Java and JSP
  • Python
  • Ruby and…

Usage and user-side functions

  • create interactive web pages
  • dynamic component of the site
  • Storage and interaction with temporary memory
  • It acts as a user interface between the site’s user and the server.
  • send request to server
  • retrieve data from server
  • interact with local storage
  • provide remote access

user-side programming languages

  • java script
  • VBScript
  • HTML (struct)
  • CSS (Design)
  • ajax
  • jQuery and…

Now is the time to look at the most important languages ​​and see which of these languages ​​is the best choice for website design. First, let’s start with the language of HTML and CSS, which are the basic languages ​​of website development.

HTML HTML is a layout and raw shell of a website. The elements of the page are the title, title, text, and links to HTML. This standard markup language is one of the major cores on the Internet and can be said to be the backbone of all web pages. HTML5 is the latest version of HTML that is published and is a dynamic language; This means that it can produce beautiful little code with a little coding.

CSS CSS is a language in which users can specify the style and format of website pages and tabs. If CSS comes with HTML, it allows the developer to define pages with different formats and appearance on the site. Colors, layers, and fonts are stored in a specified file that is separate from the web page’s core code. These two languages ​​??provide the basic structure and style information for creating a static page (a static page is a page that will be displayed to all visitors in a form with each device and browser). Now that many web pages are dynamic face designed, many site users today do not welcome static sites. To create more complex pages, you need to use advanced server-side and client-side scripts.

See also  Best Programming Language for Site Design

Java Script JavaScript is a programming language that brings animations, games, apps, interactions and other interactive content to the site and brings the site to life. After HTML and CSS, Javascript is most commonly used in user-side scripts. Some JavaScript software can also run without communication with a web server, which means that these codes and sites that use this language are able to work without being connected to the Internet.

PHP accounts for more than 75% of the web servers that use PHP. PHP is a comprehensive programming language for servers. Importance and advantage of PHP is open source or so called open source; It also has an Internet level programming language and has a large community of support and answers to questions and bugs. PHP is compatible with various operating systems. Arvin Karen Website Design Company is capable of designing powerful and professional websites. Vishal Language was born in 2004, and now over 200 million websites around the world are designed and developed by PHP. Websites like Facebook and WordPress use this platform. PHP is a scripting language which is usually interpreted and interpreted by the interpreter. For this reason, this language is suitable for server-side programming, as it easily covers server functions and tasks that are executed repeatedly. And they do. Here are some other points about this language:

  • PHP, as we said, is an open source language and a fast prototyping language.
  • It is also compatible with Unix operating systems, as it is compatible with Windows operating systems.
  • Industries that frequently use PHP are mostly in IP startup businesses, advertising industries, small software organizations, as well as agencies and multimedia companies.
  • The PHP language can be embedded directly into HTML.
See also  How Good Is Java for Mobile Game Development?

Java Java Java is a server-side scripting language used for large-scale websites with high traffic. On-site websites such as Amazon Amazon and the Apple App Store have Java-based frameworks. One reason for the popularity of high-traffic sites and their use of this programming language is that it is faster in speed tests than other languages ​​in first tests. This feature makes the software on the server run faster for large-scale sites.

Python Python is a high-level, high-level programming language with an emphasis on readable code. For web developers, this means they are working with fewer lines of code than in other popular languages. Python does this through a large standard library, which keeps the actual code short and simple. This library is a file containing pre-written practical code that is provided by the community members for Python development and can be downloaded and used by these libraries when needed. Like Java, Python is designed for web servers with high traffic volumes. Yahoo Maps is an example of sites that use Python.

Continue Reading

Trending

Copyright © 2017 Zox News Theme. Theme by MVP Themes, powered by WordPress.