Sun Microsystems acquistion by Oracle and its effects

Link wikipedia article on the acquisition

Support for the Eclipse IDE
Of course Java is now used on the Android platform, and I notice that recently support for Eclipse IDE has also been dropped moving to Android Studio (which I downloaded today for the first time – review to come later)

Android Studio replaces Eclipse
Link to wikipedia article on Android Studio
According to wikipedia, the first stable version of Android Studio was released in December 2014 (which of course makes me six months behind most people in getting it – what’s new?).

A neat trick for Laying out buttons on a JFrame

Hi Folks,

There is a neat little trick towards the end of the program given below for laying out the buttons in your Frame. Here is the relevant piece of code with the neat trick, proving there are some ingenious minds out there:

 //Add the number buttons 
    for (int i=1;i<10;i++) { 
      addButton(buttonPanel, String.valueOf(i));
 }

And here is the complete program:

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import javax.swing.JFrame; 
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container; 

public class SimpleCalc { 
    JFrame guiFrame; 
    JPanel buttonPanel; 
    JTextField numberCalc;
    int calcOperation = 0;
    int currentCalc; 

    //Note: Typically the main method will be in a //separate class. As this is a simple one class 
    //example it's all in the one class.
    public static void main(String[] args) { 
    //Use the event dispatch thread for Swing components 
    EventQueue.invokeLater(new Runnable() { 
    @Override public void run() { 
    new SimpleCalc(); 
    } 
   }
 );
}  

    public SimpleCalc() {
    guiFrame = new JFrame(); 
    //make sure the program exits when the frame closes 
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    guiFrame.setTitle("Simple Calculator"); 
    guiFrame.setSize(300,300); 
    //This will center the JFrame in the middle of the screen
    guiFrame.setLocationRelativeTo(null); 
    numberCalc = new JTextField();
    numberCalc.setHorizontalAlignment(JTextField.RIGHT); 
    numberCalc.setEditable(false); 
    guiFrame.add(numberCalc, BorderLayout.NORTH); 
    buttonPanel = new JPanel(); 
    //Make a Grid that has three rows and four columns 
    buttonPanel.setLayout(new GridLayout(4,3)); 
    guiFrame.add(buttonPanel, BorderLayout.CENTER);
     //Add the number buttons 
    for (int i=1;i<10;i++) { 
      addButton(buttonPanel, String.valueOf(i));
    }  
    //Add the operation buttons 
    JButton addButton = new JButton("+"); 
    addButton.setActionCommand("+"); 
    JButton subButton = new JButton("-"); 
    subButton.setActionCommand("-"); 
    JButton equalsButton = new JButton("=");
    equalsButton.setActionCommand("="); 
    buttonPanel.add(addButton);
    buttonPanel.add(subButton);
    buttonPanel.add(equalsButton); 
    guiFrame.setVisible(true); 

    } 

    //All the buttons are following the same pattern
    //so create them all in one place.
    private void addButton(Container parent, String name) {
    JButton but = new JButton(name); 
    but.setActionCommand(name); parent.add(but);
    } 
 }

Creating your first Java Applet


import java.awt.*;
import javax.swing.*;

public class FirstApplet extends JApplet{

private static final long serialVersionUID = 1L;

public void paint(Graphics g)
{
super.paint(g);//s is lowercase
g.drawString("Applet essential methods:", 50, 100);
g.drawString(".init()", 55, 120);
g.drawString(".paint()", 55, 140);
g.drawString(".start()", 55, 160);
g.drawString(".stop()", 55, 180);
g.drawString(".Destroy()", 55, 200);
}

}

Calling a second class inside the first class in your new package

Hi Folks,

So,  you have created a new Java Package (see my post on Creating your own Java Package in Eclipse) and you have added your first class to the Package (e.g. MyClass.java).

So next, I want to show how to add a second class to your new package and call a method from the second class (SecondClass.java) within the first Class(MyClass.java).

Steps to Follow:

1. Right Click on your package in the Package Explorer in Eclipse.

2. Select New>Class and enter a name for the New class (e.g. SecondClass). Make sure the package showing is your Java Package in the Package TextBox as shown below:

package7

Click finish and your new class will be displayed in the Workbench.