Explore BrainMass

Programming > Java

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Applet program that finds an inverse matrix

Applet program that accepts a 2x2 matrix and finds its inverse matrix if any. It seems easy, but I am having a problem getting it to work.

© BrainMass Inc. brainmass.com October 24, 2018, 7:11 pm ad1c9bdddf

Solution Preview

Dear my friend
We are so happy that you have choosed Brainmass to get help.
We are so interested to help you and your friend to get what you need.
I have found this code in my files for you, which is completely usefull for any operaion on metices. I hope to be usefull.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class MatrixCalculator {

private boolean DEBUG = true;

private boolean INFO = true;

private static int max = 100;

private static int decimals = 3;

private JLabel statusBar;

private JTextArea taA, taB, taC;

private int iDF = 0;

private int n = 4;

private static NumberFormat nf;

public Component createComponents() {

/* == MATRICES == */
taA = new JTextArea();
taB = new JTextArea();
taC = new JTextArea();

JPanel paneMs = new JPanel();
paneMs.setLayout(new BoxLayout(paneMs, BoxLayout.X_AXIS));
paneMs.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
paneMs.add(MatrixPane("Matrix A", taA));
paneMs.add(Box.createRigidArea(new Dimension(10, 0)));
paneMs.add(MatrixPane("Matrix B", taB));
paneMs.add(Box.createRigidArea(new Dimension(10, 0)));
paneMs.add(MatrixPane("Matrix C", taC));

JPanel paneBtn = new JPanel();
paneBtn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
paneBtn.setLayout(new GridLayout(3, 3));
JButton btnApB = new JButton("A + B = C");
JButton btnAmB = new JButton("A * B = C");
JButton btnBmA = new JButton("B * A = C");
JButton btnAdjA = new JButton("adjoint(A) = C");
JButton btnInvA = new JButton("inverse(A) = C");
JButton btnInvB = new JButton("inverse(B) = C");
JButton btnTrnsA = new JButton("transpose(A) = C");
JButton btnDetA = new JButton("determ(A) = C");
JButton btnDetB = new JButton("determ(B) = C");

/* == ADD BUTTON Listeners == */
btnApB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
ReadInMatrix(taB)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);

btnAmB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
ReadInMatrixNotSquare(taB)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);

btnBmA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
ReadInMatrixNotSquare(taA)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);

btnInvA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
DisplayMatrix(Inverse(ReadInMatrix(taA)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);

btnInvB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try ...

See Also This Related BrainMass Solution

Java programming - Text printing

Please see below. I am really confused on these questions and would love any guidance you could give. Examples are attached. Thanks so much in advance! (see attachment)

Compile a two-line text-printing program, similar to the Java welcome programming
examples on pp. 37, 43, 45, and 46 of the text, using one of the techniques explained in
Ch. 2. The first line should display the following text: "Hi, my name is [insert your name]."
The second line should display the following text: "I was born in [insert your birth place].

View Full Posting Details