Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, May 2, 2016

Scala IDE Issues

1. Error : Cross compiled with an incompatible version of scala (2.10.0) while building scala-application.
  Solution : If you are installed new version of scala and that is compiled. But ScalaIDE will provide built-in Scala 2.10.0 version. Over here you are able to see 2 Scala versions.
  Go to the Project Build Path -> Libraries -> select the Scala Library (currently scala 2.11.7 in my eclipse) -> Edit
       You can see the 4 types of Scala Library Containers
               - Latest 2.11 bundle (dynamic)
               - Latest 2.10 bundle (dynamic)
               - Fixed Scala Library container ( 2.11.7)
               - Fixed Scala Library container (2.10.6)

2. After buildig the project , Java Library automatically changed to the 1.6 version even if we changed to 1.8
    Solution: In pom.xml we had the below properties while creating maven-scala project
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
   The above paremeters are pointing to 1.6 means after build the project, The project preferences change to Java1.6
To fix the above problem you can always change the version number.
For example: If we want to point the project to Java 1.8
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

3. Error: Could not find or load main class com.test.scala.CountWord
   Solution: By default Scala Compiler points to 1.6JVM. If you change the Scala compiler jvm1.6 to jvm1.8 then you will get the error as "Could not find or load main class Error".
        Project -> right click -> Build Path -> Scala Compiler change to jvm1.6 by default one then problem solves.

Sunday, August 3, 2014

Swing Progress Bar example in JAVA

SwingWorker Progress Bar example is creating progress bar and it closes the progressbar automatically when it's done.
We need to provide the progress bar while running the application to increase the user-friendly.
In this program we are building the progress bar with Swing framework.
This program indicates how much task is completed and same thing shows in the progressbar.

Source code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;

public class MyProgressBarTest extends JFrame {
    private static final long serialVersionUID = 1L;

    private static JProgressBar progressBar;
    private static JLabel waitLabel = new JLabel("Please wait...");

    public static void main(String[] args) {
        MyProgressBarTest obj = new MyProgressBarTest();
        obj.createGUI();
    }

    public void createGUI() {
        JPanel panel = new JPanel();
        JButton button = new JButton("Progress");

        progressBar = new JProgressBar();
        progressBar.setVisible(false);
        waitLabel.setVisible(false);
        panel.add(waitLabel);
        panel.add(progressBar);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {

                SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                    @Override
                    protected Void doInBackground() throws Exception {

                        // mimic some long-running process here...
                        calculateResult();
                        return null;
                    }
                    //actual code is running on backend of progress bar
                    public void calculateResult() {
                        for (int i = 0; i < 300000; i++) {
                            System.out.println("Progress Bar: " + i);
                        }
                    }
                    //disable the progressbar and waitlabel when task completed
                    protected void done() {
                        progressBar.setVisible(false);
                        waitLabel.setVisible(false);
                    }
                };

                mySwingWorker.execute();

                progressBar.setIndeterminate(true);
                progressBar.setVisible(true);
                waitLabel.setVisible(true);

            }
        });

        panel.add(button);
        add(panel);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        pack();
        setSize(200, 300);
        setVisible(true);
    }
}