Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

8.7 HTML ,CSS AND JAVA.

 ads

HTML ,CSS AND JAVA.

ads


Can you build desktop applications using HTML, CSS and Javascript?

The answer is yes. 😄

This article primarily focuses on how to build desktop applications using Electron, using web technologies such as HTML, CSS, and Javascript.

ads

Electron
Electron can be used to build desktop apps using HTML, CSS and Javascript. Also, these apps work on multiple platforms such as Windows, Mac, and Linux.

ads

Electron combines Chromium and NodeJS in a single runtime environment. This allows you to run HTML, CSS, and Javascript code as desktop applications.

ads

Electron Forge If you use
Electron directly, you need to set it up manually before building your application. Also, if you use Angular, React, Vue, or any other framework or library, you'll need to manually configure this.

ads

Electron Forge makes the above task easier.

Provides templated applications using Angular, React, Vue, and other frameworks to avoid additional manual setup.

ads

It also provides an easy way to build and package your application. It also provides many other features mentioned in the documentation.

Prerequisites
Make sure NodeJS is installed. You can install it from here.

Install Electron Forge globally using the following command: -desktop-app-electronjs is the name of your application
Execution of the above command will take some time.

ads

Once the execution is finished, start the application with the following command:

cd simple-desktop-app-electronjs
npm start
This will open a window similar to the one shown below:

ads


Existing folder Understanding Structure and Code
Applications have a specific folder structure. Here are some important things about this folder structure.

ads

package.json
This contains information about the application being built, all dependencies required by the application, and some scripts. Some scripts are already preconfigured and new scripts can be added.

ads

The config.forge path contains all configuration specific to ElectronJS. For example, make-targets is used to specify target makefiles for different platforms such as Windows, Mac, and Linux.

ads

And package.json has "main": "src/index.js", indicating that src/index.js is the starting point of the application

ads

src/index.js
package. According to json, index
js is the main script. The process that executes the main script is called the main process. So the main process runs the index.js script.

The main process is used to display GUI elements. This is done by creating a website.

Each web page created runs in a process called the renderer process.

ads

Main Process and Renderer Process
The purpose of the main process is to render web pages using BrowserWindow instances.

ads

The BrowserWindow instance uses a renderer process to run each web page.

Each app has only one main process, but many renderer processes.

ads

It is also possible to communicate between the main and renderer processes. However, this is beyond the scope of this article.

ads


Electron Architecture shows the main and renderer processes. File names may vary.
abc
html will be displayed as the second web page in the above architecture. But in our code there is no second web page.

ads

src/index.html
index.js loads the index.html file into a new BrowserWindow instance.

ads

This basically means that index.js will create a new GUI window and load the index.html web page. The index.html web page runs in its own renderer process.

ads

Code Explained in index.js Most of the code written in
index.js has good comments explaining what it does. Here are some important points to consider in your index
js:

ads

mainWindow = new BrowserWindow({
width: 800,
height: 600,
});

ads

// Load the app's index.html.
mainWindow.loadURL(`file://${__dirname}/index.html`);
The code snippet above basically creates a BrowserWindow instance and loads index.html into the BrowserWindow.

ads

You can see that the app is heavily used in the code. For example, let's look at the following code snippet:

ads

app.on('ready', createWindow);
-App
 is used to control the application's event lifecycle.

The above code snippet tells us to load the first window when the application is ready.

Similarly, the app can be used to perform other actions for different events. For example, it can be used to perform actions just before the application exits.

ads

Let's Create a Temperature Conversion Desktop Application
Let's use the same application we used before, with a few modifications, to create a temperature conversion application.

ads

First, let's install bootstrap with this command:

npm install bootstrap --save
Copy the following code into src/index.html:

ads





./node_modules/bootstrap/dist/css/bootstrap.min.css">


ads

Temperature converter

ads




ads

id=" Fahrenheit " onkeyup="FahrenheitToCelcius()">


ads




above code does the following:

ads

Creates a text field with ID Celsius Every time something is typed into this text field, the function celciusToFahrenheit() is called
Creates a text field with ID Fahrenheit every time something is entered in this text field called FahrenheitToCelcius() a new value called
is entered in the Celcius text box, the value of th T extfeld Fahrenheit gives the same temperature in Fahrenheit

ads

If you enter a new value in the Fahrenheit text box, the Celsius text box value will display the same temperature in degrees Celsius,
. There are two
 functions in renderer.js that perform the temperature conversion.

Create a file named renderer.js in src. Paste the following code:

ads
function celciusToFahrenheit(){
let celcius = document.getElementById('celcius')

ads

Can you build desktop applications using HTML, CSS and Javascript?

The answer is yes. 😄

This article primarily focuses on how to build desktop applications using Electron, using web technologies such as HTML, CSS, and Javascript.

ads

Electron
Electron can be used to build desktop apps using HTML, CSS and Javascript. Also, these apps work on multiple platforms such as Windows, Mac, and Linux.

ads

Electron combines Chromium and NodeJS in a single runtime environment. This allows you to run HTML, CSS, and Javascript code as desktop applications.

ads

Electron Forge If you use
Electron directly, you need to set it up manually before building your application. Also, if you use Angular, React, Vue, or any other framework or library, you'll need to manually configure this.

ads

Electron Forge makes the above task easier.

Provides templated applications using Angular, React, Vue, and other frameworks to avoid additional manual setup.

ads

It also provides an easy way to build and package your application. It also provides many other features mentioned in the documentation.

Prerequisites
Make sure NodeJS is installed. You can install it from here.

Install Electron Forge globally using the following command: -desktop-app-electronjs is the name of your application
Execution of the above command will take some time.

ads

Once the execution is finished, start the application with the following command:

cd simple-desktop-app-electronjs
npm start
This will open a window similar to the one shown below:

ads


Existing folder Understanding Structure and Code
Applications have a specific folder structure. Here are some important things about this folder structure.

ads

package.json
This contains information about the application being built, all dependencies required by the application, and some scripts. Some scripts are already preconfigured and new scripts can be added.

ads

The config.forge path contains all configuration specific to ElectronJS. For example, make-targets is used to specify target makefiles for different platforms such as Windows, Mac, and Linux.

ads

And package.json has "main": "src/index.js", indicating that src/index.js is the starting point of the application

ads

src/index.js
package. According to json, index
js is the main script. The process that executes the main script is called the main process. So the main process runs the index.js script.

The main process is used to display GUI elements. This is done by creating a website.

Each web page created runs in a process called the renderer process.

ads

Main Process and Renderer Process
The purpose of the main process is to render web pages using BrowserWindow instances.

ads

The BrowserWindow instance uses a renderer process to run each web page.

Each app has only one main process, but many renderer processes.

ads

It is also possible to communicate between the main and renderer processes. However, this is beyond the scope of this article.

ads


Electron Architecture shows the main and renderer processes. File names may vary.
abc
html will be displayed as the second web page in the above architecture. But in our code there is no second web page.

ads

src/index.html
index.js loads the index.html file into a new BrowserWindow instance.

ads

This basically means that index.js will create a new GUI window and load the index.html web page. The index.html web page runs in its own renderer process.

ads

Code Explained in index.js Most of the code written in
index.js has good comments explaining what it does. Here are some important points to consider in your index
js:

ads

mainWindow = new BrowserWindow({
width: 800,
height: 600,
});

ads

// Load the app's index.html.
mainWindow.loadURL(`file://${__dirname}/index.html`);
The code snippet above basically creates a BrowserWindow instance and loads index.html into the BrowserWindow.

ads

You can see that the app is heavily used in the code. For example, let's look at the following code snippet:

ads

app.on('ready', createWindow);
-App
 is used to control the application's event lifecycle.

The above code snippet tells us to load the first window when the application is ready.

Similarly, the app can be used to perform other actions for different events. For example, it can be used to perform actions just before the application exits.

ads

Let's Create a Temperature Conversion Desktop Application
Let's use the same application we used before, with a few modifications, to create a temperature conversion application.

ads

First, let's install bootstrap with this command:

npm install bootstrap --save
Copy the following code into src/index.html:

ads





./node_modules/bootstrap/dist/css/bootstrap.min.css">


ads

Temperature converter

ads




ads

id=" Fahrenheit " onkeyup="FahrenheitToCelcius()">


ads




above code does the following:

ads

Creates a text field with ID Celsius Every time something is typed into this text field, the function celciusToFahrenheit() is called
Creates a text field with ID Fahrenheit every time something is entered in this text field called FahrenheitToCelcius() a new value called
is entered in the Celcius text box, the value of th T extfeld Fahrenheit gives the same temperature in Fahrenheit

ads

If you enter a new value in the Fahrenheit text box, the Celsius text box value will display the same temperature in degrees Celsius,
. There are two
 functions in renderer.js that perform the temperature conversion.

Create a file named renderer.js in src. Paste the following code:

ads
function celciusToFahrenheit(){let celcius = document.getElementById('celcius')

ads

Post a Comment

0 Comments