Calculating and displaying the Length of the side of a triangle

Hi everyone. I am currently working on Dragging and Stretching a triangle on screen. Ive got it working to a certain extent but the only problem is that whenever I go to the point from which i have to drag my triangle i.e. the Left hand Corner of the BAse at exactly 300,300 it redraws a new triangle below the existing one and then when i stretch it from the top and the right it leaves a trail of triangles everytime. But when i resize my window it clears the trail only to start agian when I drag or stretch it...
All my code for wahtever I have done is displayed below. I would appreciate all the help that any one can offer.
Secondly , as I stretch my triangle I would like to calculate My Length of the hypotenuse and the other 2 sides as they change and display it in System.out.println for now...
PLEASE HELP
the code is
This is my Main Form --- Interactive Geometry.java
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
* InteractiveGeometry.java
* Created on 30 November 2004, 20:29
* @author  Kripa Bhojwani
public class InteractiveGeometry extends javax.swing.JFrame {
    public EastPanel eastpanel;
    public Container container;
    public GeomPanel gp;
    public boolean pressed = false;
    public boolean pressT = false;
    public boolean pressR = false;
    /** Creates new form InteractiveGeometry */
    public InteractiveGeometry() {
        initComponents();
        eastpanel = new EastPanel();
        container = new Container();
        Model model = new Model(300,150,450,300,300,300);
        gp = new GeomPanel(model);
        container = getContentPane();
        container.add(eastpanel,BorderLayout.EAST);
        container.add(gp,BorderLayout.CENTER);
        setSize(1400,9950);
        gp.addMouseMotionListener(
        new MouseMotionListener() { //anonymous inner class
            //handle mouse drag event
            public void mouseDragged(MouseEvent me) {
                setTitle("Dragging: x=" + me.getX() + "; y=" + me.getY());
            public void mouseMoved(MouseEvent me) {
                setTitle("Moving: x=" + me.getX() + "; y=" + me.getY());
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
        jMenuBar2.setBackground(new java.awt.Color(0, 102, 204));
        jMenu2.setBackground(new java.awt.Color(222, 222, 238));
        jMenu2.setText("File");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
        jMenuItem1.setBackground(new java.awt.Color(204, 255, 255));
        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
        jMenu2.add(jMenuItem1);
        jMenuBar2.add(jMenu2);
        jMenu1.setBackground(new java.awt.Color(199, 215, 255));
        jMenu1.setText("Theorem ");
        jMenuItem2.setText("Pythagoras Theorem");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
        jMenu1.add(jMenuItem2);
        jMenuBar2.add(jMenu1);
        setJMenuBar(jMenuBar2);
        pack();
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    private void formMouseDragged(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    private void formMouseMoved(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    public void mouseDragged(MouseEvent me) {
        setTitle("Dragging: x=" + me.getX() + "; y=" + me.getY());
    private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        System.exit(0);
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
     * @param args the command line arguments
    public static void main(String args[]) {
        InteractiveGeometry ig = new InteractiveGeometry();
        ig.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ig.show();
        // new InteractiveGeometry().show();
    // Variables declaration - do not modify
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    // End of variables declaration
This is my Panel -- GeomPanel.java which draws everything -- /*
* GeomPanel.java
* Created on 30 November 2004, 20:29
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.Graphics.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import javax.swing.event.TableModelListener;
import javax.swing.JScrollPane;
import javax.swing.event.*;
import java.awt.Dimension;
import java.awt.Container.*;
* @author Kripa Bhojwani
public class GeomPanel extends javax.swing.JPanel implements Observer, MouseMotionListener, MouseListener {
private Model model;
private boolean pressed = false;
private boolean pressT = false;
private boolean pressR = false;
/** Creates new form GeomPanel */
public GeomPanel(Model model) {
this.model = model;
model.addObserver(this);
addMouseListener(this);
addMouseMotionListener(this);
initComponents();
setBackground(Color.getHSBColor(6,600,660));
public void paintComponent(Graphics gfx) {
Graphics2D g = (Graphics2D) gfx;
Point tc = model.getTop();
Point lc = model.getLeft();
Point rc = model.getRight();
Point2D.Double p1 = new Point2D.Double(tc.getX(),tc.getY());
Point2D.Double p2 = new Point2D.Double(lc.getX(),lc.getY());
Point2D.Double p3 = new Point2D.Double(rc.getX(),rc.getY());
Line2D.Double line = new Line2D.Double(p1, p2);
Line2D.Double line1 = new Line2D.Double(p2, p3);
Line2D.Double line2 = new Line2D.Double(p1, p3);
g.setColor(Color.BLACK);
g.draw(line);
g.draw(line2);
g.draw(line1);
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
setLayout(new java.awt.BorderLayout());
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
formMouseDragged(evt);
private void formMouseDragged(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
public void mouseClicked(MouseEvent e) {
public void mouseDragged(MouseEvent e) {
System.out.println("Dragged at "+ e.getX()+ "," + e.getY());
if(pressed == true){
model.setLeft(e.getX() , e.getY());
else if(pressT == true){
model.setTop(e.getX() , e.getY());
else if (pressR == true){
model.setRight(e.getX(), e.getY());
else{
pressed = false;
pressT= false;
pressR=false;
repaint();
public void mouseEntered(MouseEvent e) {
public void mouseExited(MouseEvent e) {
public void mouseMoved(MouseEvent e) {
System.out.println("Mouse at " + e.getX() +"," + e.getY());
public void mousePressed(MouseEvent e) {
if (model.getLeft().getX()== e.getX() && model.getLeft().getY()== e.getY()){
pressed = true;
else if (model.getTop().getX()==e.getX() && model.getTop().getY()==e.getY()){
pressT = true;
else if(model.getRight().getX() == e.getX() && model.getRight().getY()==e.getY()){
pressR = true;
// else if(model.getCircle().getX() == e.getX() && model.getCircle().getY() == e.getY()){
// inoval = true;
else {
pressed =false;
pressT = false;
pressR = false;
} repaint();
public void mouseReleased(MouseEvent e) {
if(pressed == true){
model.setLeft(e.getX(),e.getY());
else if (pressT ==true ){
model.setTop(e.getX(), e.getY());
else if(pressR ==true){
model.setRight(e.getX(),e.getY());
else {
pressed = false;
pressT = false;
pressR = false;
repaint();
public void update(Observable o, Object arg) {
repaint();
// Variables declaration - do not modify
// End of variables declaration
This is my Model class called Model.java which Holds all teh data for my triangle
import java.awt.Point;
import java.util.Observable;
* Model.java
* Created on 05 December 2004, 14:11
* @author  Kripa Bhojwani
public class Model extends Observable{
    private int  x1,x2,x3, y1,y2,y3;
    private int _transx;
    private int _transy;
    private int _c;
    private int _d;
    /** Creates a new instance of Model */
    public Model(int x1, int y1, int x2, int y2, int x3, int y3) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.x3 = x3;
        this.y3 = y3;
        setChanged();
        notifyObservers();
    public void setTop(int x1, int y1){
        //this.x1 =x1;
        this.y1= y1;
        setChanged();
        notifyObservers();
    public void setRight(int x2, int y2){
        this.x2 = x2;
        // this.y2 =y2;
        setChanged();
        notifyObservers();
    public void setLeft(int x3, int y3){
        _transx = x3 - this.x3;
        _transy = y3 - this.y3;
        this.x3 += _transx;
        this.y3 += _transy;
        this.y2 += _transy;
        this.x2 += _transx;
        this.x1 += _transx;
        this.y1 += _transy;
        setChanged();
        notifyObservers();
    public Point getTop(){
        Point p = new Point(x1,y1);
        return p;
    public Point getRight(){
        Point p1 = new Point(x2,y2);
        return p1;
    public Point getLeft(){
        Point p3 = new Point(x3,y3);
        return p3;
    public void update() {
        setChanged();
        notifyObservers();
This is my TableModel which is the JTable to display all the Cordinates and Lengths and other Measurements like angles etc./*
* TableModel.java
* Created on 03 December 2004, 15:08
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import java.util.Observer;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;
* @author Kripa Bhojwani
public class TableModel extends AbstractTableModel implements Observer{
private String[] columnNames = {"Point", "X Coordinate", "Y Coordinate"};
private Object[][] data = {};
private int rowCount;
private int columnCount;
/** Creates a new instance of TableModel */
public TableModel() {
rowCount = 0;
columnCount = 3;
public int getColumnCount() {
return columnCount;
public int getRowCount() {
return rowCount;
public String getColumnName(int col) {
return columnNames[col];
public void setColumnName (String[] name){
columnNames = name;
public void setValueAt(Object obj, int row, int col) {
data[row][col] = obj;
fireTableCellUpdated(row, col);
TableModelEvent tme = new TableModelEvent(this);
fireTableChanged(tme);
public Object getValueAt(int row, int col) {
return data[row][col];
public void update(java.util.Observable o, Object arg) {
This is the Panel on the east side of My Main application form which will display all the measurements and Cordinates ---EastPanel.java
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelListener;
import java.awt.Dimension;
* EastPanel.java
* Created on 04 December 2004, 23:07
* @author  Kripa Bhojwani
public class EastPanel extends javax.swing.JPanel implements TableModelListener{
    private TableModel tm;
    /** Creates new form EastPanel */
    public EastPanel() {   
      initComponents();
        tm = new TableModel();
        JTable table1 = new JTable(tm);
        table1.setPreferredScrollableViewportSize(new Dimension(250,264));
        table1.getModel().addTableModelListener(this);
        JScrollPane sp = new JScrollPane(table1);
        add(sp,BorderLayout.EAST);
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {
        setLayout(new java.awt.BorderLayout());
    public void tableChanged(javax.swing.event.TableModelEvent e) {
    // Variables declaration - do not modify
    // End of variables declaration
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.text.NumberFormat;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableCellRenderer;
public class G
public G()
TriangleModel tri = new
ri = new TriangleModel(175,100,175,250,325,250);
TriangleView view = new TriangleView(tri);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(view.getUIPanel(),
Panel(), "North");
f.getContentPane().add(view);
f.getContentPane().add(view.getTablePanel(),
Panel(), "South");
f.setSize(500,500);
f.setLocation(200,200);
f.setVisible(true);
public static void main(String[] args)
new G();
class TriangleModel // (x1,
y1)
{                                         //      |\
static final int SIDES = 3; // | \
private int cx, cy; // |
| \
Polygon triangle; // |_
|_ _\ (x3, y3)
int selectedIndex; // (x2,
(x2, y2)
NumberFormat nf;
Line2D[] medians;
Point2D centroid;
public TriangleModel(int x1, int y1, int x2, int
int y2, int x3, int y3)
int[] x = new int[] { x1, x2, x3 };
int[] y = new int[] { y1, y2, y3 };
triangle = new Polygon(x, y, SIDES);
nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(1);
public boolean contains(Point p)
// Polygon.contains doesn't work well enough
return (new Area(triangle)).contains(p);
public boolean isLineSelected(Rectangle r)
Line2D line = new Line2D.Double();
for(int j = 0; j < SIDES; j++)
int[] x = triangle.xpoints;
int[] y = triangle.ypoints;
int x1 = x[j];
int y1 = y[j];
int x2 = x[(j + 1) % SIDES];
int y2 = y[(j + 1) % SIDES];
line.setLine(x1, y1, x2, y2);
if(line.intersects(r))
selectedIndex = j;
return true;
selectedIndex = -1;
return false;
* Only works for right triangle with right angle
angle at (x2, y2)
public void moveSide(int dx, int dy, Point p)
int[] x = triangle.xpoints;
int[] y = triangle.ypoints;
switch(selectedIndex)
case 0:
x[0] += dx;
x[1] += dx;
break;
case 1:
y[1] += dy;
y[2] += dy;
break;
case 2:
double rise = y[2] - y[0];
double run = x[2] - x[0];
double slope = rise/run;
// rise / run == (y[2] - p.y) / (x[2]
] - p.y) / (x[2] - p.x)
x[2] = p.x + (int)((y[2] - p.y) /
)((y[2] - p.y) / slope);
// rise / run == (p.y - y[0]) / (p.x
y - y[0]) / (p.x - x[0])
y[0] = p.y - (int)((p.x - x[0]) *
)((p.x - x[0]) * slope);
public void translate(int dx, int dy)
triangle.translate(dx, dy);
public Polygon getTriangle()
return triangle;
public String findCentroid()
int[] x = triangle.xpoints;
int[] y = triangle.ypoints;
// construct the medians defined as the line
the line from
// any vertex to the midpoint of the opposite
opposite line
medians = new Line2D[x.length];
for(int j = 0; j < x.length; j++)
int next = (j + 1) % x.length;
int last = (j + 2) % x.length;
Point2D vertex = new Point2D.Double(x[j],
Double(x[j], y[j]);
// get midpoint of line opposite vertex
double dx = ((double)x[last] -
le)x[last] - x[next])/2;
double dy = ((double)y[last] -
le)y[last] - y[next])/2;
Point2D oppLineCenter = new
Center = new Point2D.Double(x[next] + dx,
y[next]
y[next] + dy);
medians[j] = new Line2D.Double(vertex,
uble(vertex, oppLineCenter);
// centroid is located on any median 2/3 the
2/3 the way from the
// vertex (P1) to the midpoint (P2) on the
) on the opposite side
double[] lengths = getSideLengths();
double dx = (medians[0].getX2() -
etX2() - medians[0].getX1())*2/3;
double dy = (medians[0].getY2() -
etY2() - medians[0].getY1())*2/3;
double px = medians[0].getX1() + dx;
double py = medians[0].getY1() + dy;
//System.out.println("px = " + nf.format(px)
rmat(px) +
// "\tpy = " +
py = " + nf.format(py));
centroid = new Point2D.Double(px, py);
return "(" + nf.format(px) + ", " +
", " + nf.format(py) + ")";
public String[] getAngles()
double[] lengths = getSideLengths();
String[] vertices = new
es = new String[lengths.length];
for(int j = 0; j < lengths.length; j++)
int opp = (j + 1) % lengths.length;
int last = (j + 2) % lengths.length;
double top = lengths[j] * lengths[j] +
lengths[last] *
lengths[last] * lengths[last] -
lengths[opp] *
lengths[opp] * lengths[opp];
double divisor = 2 * lengths[j] *
lengths[j] * lengths[last];
double vertex = Math.acos(top /
h.acos(top / divisor);
vertices[j] =
ertices[j] = nf.format(Math.toDegrees(vertex));
return vertices;
public String[] getLengths()
double[] lengths = getSideLengths();
String[] lengthStrs = new
rs = new String[lengths.length];
for(int j = 0; j < lengthStrs.length; j++)
lengthStrs[j] = nf.format(lengths[j]);
return lengthStrs;
public String[] getSquares()
double[] lengths = getSideLengths();
String[] squareStrs = new
rs = new String[lengths.length];
for(int j = 0; j < squareStrs.length; j++)
squareStrs[j] = nf.format(lengths[j] *
lengths[j] * lengths[j]);
return squareStrs;
private double[] getSideLengths()
int[] x = triangle.xpoints;
int[] y = triangle.ypoints;
double[] lengths = new double[SIDES];
for(int j = 0; j < SIDES; j++)
int next = (j + 1) % SIDES;
lengths[j] = Point.distance(x[j], y[j],
(x[j], y[j], x[next], y[next]);
return lengths;
class TriangleView extends JPanel
private TriangleModel model;
private Polygon triangle;
private JTable table;
private JLabel centroidLabel;
private boolean showConstruction;
TriangleControl control;
public TriangleView(TriangleModel model)
this.model = model;
triangle = model.getTriangle();
showConstruction = false;
control = new TriangleControl(this);
addMouseListener(control);
addMouseMotionListener(control);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.draw(triangle);
if(model.medians == null)
centroidLabel.setText("centroid location:
id location: " + model.findCentroid());
// draw medians and centroid point
if(showConstruction && !control.dragging)
g2.setPaint(Color.red);
for(int j = 0; j < 3; j++)
g2.draw(model.medians[j]);
g2.setPaint(Color.blue);
g2.fill(new
g2.fill(new Ellipse2D.Double(model.centroid.getX() -
2,
model.centroid.getY()
model.centroid.getY() - 2, 4, 4));
public TriangleModel getModel()
return model;
public JTable getTable()
return table;
public JLabel getCentroidLabel()
return centroidLabel;
public JPanel getUIPanel()
JCheckBox showCon = new JCheckBox("show
ox("show construction");
showCon.addActionListener(new
ener(new ActionListener()
public void actionPerformed(ActionEvent
(ActionEvent e)
boolean state =
boolean state =
((JCheckBox)e.getSource()).isSelected();
showConstruction = state;
repaint();
JPanel panel = new JPanel();
panel.add(showCon);
return panel;
public JPanel getTablePanel()
String[] headers = new String[] { "", "", "",
// row and column data labels
String[] rowHeaders = {
"sides", "lengths", "squares", "angles",
", "angles", "degrees"
String[] sidesRow = { "vertical",
rtical", "horizontal", "hypotenuse" };
String[] anglesRow = { "hyp to ver", "ver to
"ver to hor", "hor to hyp" };
// collect data from model
String[] angles = model.getAngles();
String[] lengths = model.getLengths();
String[] squares = model.getSquares();
String[][] allData = { sidesRow, lengths,
lengths, squares, anglesRow, angles };
int rows = 5;
int cols = 4;
Object[][] data = new Object[rows][cols];
for(int row = 0; row < rows; row++)
data[row][0] = rowHeaders[row];
for(int col = 1; col < cols; col++)
data[row][col] = allData[row][col -
lData[row][col - 1];
table = new JTable(data, headers)
public boolean isCellEditable(int row,
ble(int row, int col)
return false;
DefaultTableCellRenderer renderer =
(DefaultTableCellRenderer)table.getDefaultRenderer(St
ring.class);
renderer.setHorizontalAlignment(JLabel.CENTER);
centroidLabel = new JLabel("centroid
centroid location: ", JLabel.CENTER);
Dimension d =
sion d = centroidLabel.getPreferredSize();
d.height = table.getRowHeight();
centroidLabel.setPreferredSize(d);
JPanel panel = new JPanel(new
anel(new BorderLayout());
panel.setBorder(BorderFactory.createTitledBorder("tri
angle data"));
panel.add(table);
panel.add(centroidLabel, "South");
return panel;
class TriangleControl extends MouseInputAdapter
TriangleView view;
TriangleModel model;
Point start;
boolean dragging, altering;
Rectangle lineLens; // used for line
line selection
public TriangleControl(TriangleView tv)
view = tv;
model = view.getModel();
dragging = altering = false;
lineLens = new Rectangle(0, 0, 6, 6);
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
lineLens.setLocation(p.x - 3, p.y - 3);
// are we over a line
if(model.isLineSelected(lineLens))
start = p;
altering = true;
// or are we within the triangle
else if(model.contains(p))
start = p;
dragging = true;
public void mouseReleased(MouseEvent e)
altering = false;
dragging = false;
view.getCentroidLabel().setText("centroid
centroid location: " +
model.findCentroid());
view.repaint(); // for the construction
truction lines
public void mouseDragged(MouseEvent e)
Point p = e.getPoint();
if(altering)
int x = p.x - start.x;
int y = p.y - start.y;
model.moveSide(x, y, p);
updateTable();
view.repaint();
start = p;
else if(dragging)
int x = p.x - start.x;
int y = p.y - start.y;
model.translate(x, y);
view.repaint();
start = p;
private void updateTable()
String[] lengths = model.getLengths();
String[] squares = model.getSquares();
String[] angles = model.getAngles();
JTable table = view.getTable();
for(int j = 0; j < angles.length; j++)
table.setValueAt(lengths[j], 1, j + 1);
table.setValueAt(squares[j], 2, j + 1);
table.setValueAt(angles[j], 4, j + 1);
view.getCentroidLabel().setText("centroid
centroid location: " +
model.findCentroid());
Hey sorry mate.. ive got a nother problem.
I need to add loads of theorems to this tool. so i need a JMenu Bar called File with all the normal things. then another Menu called Theorems where i can have a list of JMenuItems with the theorem names --- Like when they click on Pythagoras Theorem it opens up all the triangle and the traingle data that u helped me with.
The thing is im using netbeans and in netbeans i can do it coz its there and all you got to do is put the components together.
Please Help
Thanks...
Sharan

Similar Messages

  • Calculating the length of the longest side of a polygon

    If you want to calculate the length of the longest side of a polygon -- for example a rectangle -- how can that be done using the standard geometrical functions of spatial in an oracle 10g2 database?
    SDO_LENGHT delivers the outline of the polygon. If have looked at the LRS functions, but could not come up with a combination that delivers me what I am looking for. Any suggestion is appreciated.

    What do you see as the longest side?
    Is that the longest stretch between 2 consecutive vertices?
    If this is the case, this sql could be of help, which could need maybe some optimisation and extension (calculates straigth distance between 2 consecutive vertices).
    select id, p_side_nr, p_side,  p_side_length
    from
    select id,  p_side_nr, p_side, sdo_geom.sdo_length(p_side, 0.005) p_side_length,  max(sdo_geom.sdo_length(p_side, 0.005)) over (partition by id) max_p_side_length
    from
    select id, p_side_nr,
           sdo_geometry(2002, NULL, NULL,
                 SDO_ELEM_INFO_ARRAY(1,2,1),
                 SDO_ORDINATE_ARRAY(startx, starty, endx, endy)
                ) p_side
    from
         select
               startp.id, startp.x startx, startp.y starty, startp.v_id p_side_nr, endp.x endx, endp.y endy, endp.v_id
         from
              select  s.id, t.id v_id, t.x, t.y
              from your_table_name s, table(sdo_util.getvertices(geometry)) t
              ) startp
              select s.id, t.id v_id, t.x, t.y
              from your_table_name s, table(sdo_util.getvertices(geometry)) t
              ) endp
         where startp.id = endp.id
         and startp.v_id = endp.v_id - 1
    ) where p_side_length = max_p_side_lengthif you do not need the geometry of that longest side, you could follow Ivan's suggestion as a shortcut by using Pythagoras.
    Edited by: lucvanlinden on Sep 2, 2008 7:48 PM

  • Display instantly the length of the text entered in the rich text editor

    Hi everybody,
    I'm developing an apex application with apex 4.1.1 and Oracle 11.2.
    I have a page in which I have a form that allows to create a new message on the database.
    A message has a title, description, text and date.
    For the text I use the item "rich editor text". The problem is that item doesn't show the length of characters entered (character counter for the textarea). In the database the corresponding column is varchar2(2000). What I do is a validation after submit that checks if the limit 2000 was exceeded or not.
    But what I want to do more is to display instantly the length of the text entered in the editor. I have tried to do that through a dynamic action. But the event "onChange" for the item "rich text editor" didn't work.
    Has anyone any idea about that issue?
    Thanks for helping.
    Kind regards,
    Edited by: Khadija Khalfallah on Apr 25, 2013 4:06 AM

    sorry about that, I missed that tidbit in your OP... well I think there is a good reason why there isn't a count character option -- due to the hidden "html" characters responsible for the "richness" (bold/color, etc) applied to the text would be difficult to count true characters.. if I was bent on doing this, I'd continue using the item you are using, but have a HIDDEN text area that is updated via javascript onkeyup for each keystroke (again, keeping in mind you'd have to filter certain keys) and then that intelligence could be used. I would probably dig through the javascript responsible for the rich text editor (is it still fckeditor??) -- there might already be code in there that isn't clearly visible to you that does this already.. alas, I see now the validity of your challenge.

  • The length of the recording and exporting truncated

    Hi there.
    It's my first venture into GarageBand. I have just a few questions.
    First, how can I tell the length of my recording without having to listen to the entire session? Dragging the indicator bar in the window to move it along takes a very long time, is there a quicker way to do this?
    Second, I have been exporting my files to iTunes to burn CD's. I am seeing that the file get's shortened in the process. It's not just a small clip, but rather edits out over 15 minutes on one file. Any thoughts? I called Apple and they knew nothing.

    To determine the length:
    - Switch the meter that shows bars and beats to minutes and seconds (by clicking on the clock icon).
    - Scroll to the end of the song.
    - Click into the timeline's ruler, and the cursor will be taken there, the meter showing the minutes and seconds.
    As for the export: Do you see the little purple triangle in the timeline, pointing to the left? That's your End of Song marker. Does it sit at the right position? If not, move it there and try exporting again. And since this little ******* is playing tricks sometimes, a more exact way of exporting is using the circle function and setting the circle section exactly from the beginning to the end of what you want to export.
    Oh, and by the way: How long is your recording? If it exceeds 999 bars, then GB will only export until bar 999, although your whole recording is still there.
    Come back and tell us what you found out!

  • The type and the length of the members of the structures

    I am making the BC-XAL program.
    Reading `XAL_Interface_Documentation_11.pdf', now I succeeded in "Reading All Saved Monitor Sets" and "Reading All Monitors of a Monitor Set". but I can't find the type and the length of the member of the Structure BAPITNDEXT, so I cannot get the Monitoring Tree of a Monitor.
    where can I get any documents or information ?

    This is how it looks in my 46c system.
    MTSYSID         SYSYSID         CHAR      8     0R/3 System, name of R/3 System                                 
    MTMCNAME        ALMCNAME        CHAR     40     0Alert: name of monitoring context                              
    MTNUMRANGE      ALTIDNUMRG      CHAR      3     0Alert: monitoring type number range (perm., temp, ...)         
    MTUID           ALTIDUID        CHAR     10     0ALert: Unique Identifier for  Monitoring Types (used in TID)   
    MTCLASS         ALTIDMTCL       CHAR      3     0Alert: monitoring type class (perf., single msg.,...)          
    MTINDEX         ALTIDINDEX      CHAR     10     0Alert: internal handle for TID                                 
    EXTINDEX        ALTIDINDEX      CHAR     10     0Alert: internal handle for TID                                 
    ALTREENUM       ALTREENUM       INT4     10     0Alert: MT Tree info: Number of tree                            
    ALIDXINTRE      ALIDXINTRE      INT4     10     0Alert: Tree Info: Index of MT in Tree                          
    ALLEVINTRE      ALLEVINTRE      INT4     10     0Alert: Tree Info: Level of MTE in Tree                         
    ALPARINTRE      ALPARINTRE      INT4     10     0Alert: Tree Info: Index of Parent of MT in Tree                
    OBJECTNAME      ALMOBJECT       CHAR     40     0Alert: Name of Monitoring Object                               
    MTNAMESHRT      ALMTNAMESH      CHAR     40     0Alert: Short Name of Monitoring Type                           
    CUSGRPNAME      ALCUSGROUP      CHAR     40     0Alert: Customization: Name of Customization Group              
    DELIVERSTA      ALDELIVSTA      INT4     10     0Alert: MT Val: Delivery Status                                 
    HIGHALVAL       ALVALUE         INT4     10     0Alert: alert value (1 = green, 2 = yellow, ....)               
    HIGHALSEV       ALSEVERITY      INT4     10     0Alert: severity (alerts, monitoring type custom..)             
    ALSYSID         SYSYSID         CHAR      8     0R/3 System, name of R/3 System                                 
    MSEGNAME        ALMSEGNAME      CHAR     40     0Alert: name of monitoring segment                              
    ALUNIQNUM       ALAIDUID        CHAR     10     0Alert: Unique Identifier to be used in AID (char10)            
    ALINDEX         ALINDEX         CHAR     10     0Alert: internal handle                                         
    ALERTDATE       ALDATE          DATS      8     0Alert: date                                                    
    ALERTTIME       ALTIME          TIMS      6     0Alert: Time value in timeformat                                
    DUMMYALIGN      ALDUMMYC2       CHAR      2     0Alert: Dummy field. Purpose: Alignment of date/time 16 byte    
    LASTVALDAT      ALDATE          DATS      8     0Alert: date                                                    
    LASTVALTIM      ALTIME          TIMS      6     0Alert: Time value in timeformat                                
    LASTVALDUM      ALDUMMYC2       CHAR      2     0Alert: Dummy field. Purpose: Alignment of date/time 16 byte    
    ACTUALVAL       ALVALUE         INT4     10     0Alert: alert value (1 = green, 2 = yellow, ....)               
    ACTUALSEV       ALSEVERITY      INT4     10     0Alert: severity (alerts, monitoring type custom..)             
    VALSYSID        SYSYSID         CHAR      8     0R/3 System, name of R/3 System                                 
    VMSEGNAME     ALMSEGNAME     CHAR     40     0     Alert: name of monitoring segment                                  
    VALUNIQNUM     ALAIDUID     CHAR     10     0     Alert: Unique Identifier to be used in AID (char10)                                  
    VALINDEX     ALINDEX     CHAR     10     0     Alert: internal handle                                  
    VALERTDATE     ALDATE     DATS     8     0     Alert: date                                  
    VALERTTIME     ALTIME     TIMS     6     0     Alert: Time value in timeformat                                  
    VALERTDUM     ALDUMMYC2     CHAR     2     0     Alert: Dummy field. Purpose: Alignment of date/time 16 byte                                  
    COUNTOFACT     ALCNTACTAL     INT4     10     0     Alert: MT Val: Count of active Alerts                                  
    COUNTSUM     ALCNTSUMAL     INT4     10     0     Alert: MT Val: Sum of Alerts in MT                                  
    VISUSERLEV     ALVISILEVL     INT4     10     0     Alert: MTE type dev cust: Visible on user level (op,exp,dev)                                  
    TDSTATUS     ALTDSTATUS     INT4     10     0
         Alert: MT: Type Def Status
    Welcome to SDN.
    Regards,
    Rich Heilman

  • How do i make a still image (photo) fit the length of the music? I record music and want to put the tracks to a video file with a still image of my business logo in the background. Any help?

    How do I make a still image (photo) fit the length of the music? I record music and want to convert the tracks to a video file with a still image of my business logo in the background. On windows movie maker you could just select "fit to music" but this program isnt as easy to figure out! Any help?

    Double-click on the still image in the project timeline to open the Inspector. In the Inspector, adjust the duration by typing in a new duration to match the length of your music. I think the limit for a still image is 10 minutes. If you need more than this, simply drag the image into the timeline again then adjust its duration. The two images will play seamlessly (no gap will be visible).
    See this iMovie Help topic:
    http://help.apple.com/imovie/#mov3a883915
    You can achieve more precision when entering durations by changing a preference in the menu item iMovie Preferences. Check (tick) the preference for Show Time As HH:MM:SS:frames. This will enable you to enter the duration of stills down to the frame level, rather than full seconds (NTSC is 30 frames per second; PAL is 25 fps). When entering times, type a colon between each time segment, such as 2:50:15, which represents 2 minutes 50 seconds and 15 frames. For 5 seconds 20 frames you would enter 5:20 and so forth.
    Note that the music will only run to the length of the video in the timeline (in your case, the still images). So, after increasing the stills duration you will need to drag the end of the music track as far as required. The stills can be dragged inwards to reduce the duration if necessary.
    John
    Message was edited by: John Cogdell - added Note

  • Hello. I have an iPad2, and iMovie software. My main problem, for the moment, is the length of the videos: I can´t create a video with more than 56 seconds. When I try, the app shuts off... Can anyone help me?

    Hello. I have an iPad2, and iMovie software. My main problem, for the moment, is the length of the videos: I can´t create a video with more than 56 seconds. When I try, the app shuts off... Can anyone help me?

    Sorry. We can't help you. It's no longer an iPhone. Apple won't touch it.
    Take it to whoever replaced the screen and see if they can help you.
    iPhones are not user servicable and Apple does not sell iPhone parts at all. I'd be surprised if you were actually able to back it up at this point. It sounds like it's completely borked.

  • I am trying to resize the the lengths of the address bar and the search bar. I could before using a "line" between them to drag to resize. But this is now not s

    I am trying to resize the the lengths of the address bar and the search bar. I could before using a "line" between them to drag to resize. But this is now not showing. Any ideas?

    There is a simple way to try and fix the Issue.
    Try '''Resetting '''Your Toolbar to Default and Resize.
    '''You can always restore the default toolbar settings by clicking Restore Default Set in the Customize Toolbar window.'''
    For more step by step way of fixing the Toolbar Arrangement, [https://support.mozilla.org/en-US/kb/customize-firefox-controls-buttons-and-toolbars?esab=a&s=reset+toolbar&r=3&as=s Look at this Link]

  • Hide and Display submit button on the Simple search page.

    Heading 1: h1 Hide and Display submit button on the Simple search page.
    I'm trying to set the enabled property of the submit button on the simple search page. The business case is to disable the button if the VO has not returned any rows.
    The Submit button is on the page button bar.
    regards
    Abhi

    Hi,
    I have already added this in my ProcessRequest, the issue I am facing is it the submit button is disabled while I load >the page which is fine. but when I do a search and the query returns rows still the submit button is disabled.---Will nt reuired SPEL here..
    ---On go button click setsession value.
    Follow below steps:
    CO PR:*
    OASubmitButtonBean continueBtn=(OASubmitButtonBean)flowLayout.findChildRecursive("continueBtn");
    if(continueBtn != null && "D".equals(oapagecontext.getSessionValue("Flag"))
    continueBtn.setDisabled(false);
    else if(continueBtn != null )
    continueBtn.setDisabled(true);
    CO PFR:_
    if(pageContext.getParameter("Go") != null)
    oapagecontext.putSessionValue("Flag","D");
    Regards
    Meher Irk
    Edited by: Meher Irk on Mar 22, 2011 7:48 PM
    Edited by: Meher Irk on Mar 22, 2011 7:48 PM

  • I am using garage band for the first time.  I dragged and dropped a song from itunes into the program and I want to extend the length of the song by repeating the first 28 measures.  I can't figure it out.  Please help

    I am using garage band for the first time.  I dragged and dropped a song from itunes into the program and I want to extend the length of the song by repeating the first 28 measures.  I can't figure it out.  Please help.  I have spent several hours trying to figure it out on my own but have not been successful.  It seems like an easy task.  Can anyone help?

    dewin1or wrote:
    I want to extend the length of the song by repeating the first 28 measures.
    split the region at the 28th measure
    http://www.bulletsandbones.com/GB/GBFAQ.html#split
    (Let the page FULLY load. The link to your answer is at the top of your screen)
    then select only the first region and option-drag it to the end of the song

  • Why does it take iMovie longer to import video than the length of the video? For example- it took 2 mins and 15 secs to import 2 mins and 4 secs of video...

    why does it take iMovie longer to import video than the length of the video? For example- it took 2 mins and 15 secs to import 2 mins and 4 secs of video...

    It's not like playing a tape. It has to convert it from whatever format you currently have into a codec suitable for editing (Apple Intermediate). This will take longer or shorter depending how compressed your original format is, and on the ability of your CPUs to catch up.
    Matt

  • The length of the password entry field in the BEx Analyser

    Hi,
    The password is 8 characters in the BW system.
    When users changing their newly assigned passwords. When logging into the BEx Analyser, and prompted to change the password, a password entry box is displayed, with an entry field longer then 8 characters. Some users are therefore entering passwords longer then 8 characters. This is fine when they first login, but when they try come back to the system, their logon fails.
    Can something be done to restrict the length of the password entry field in the BEx Analyser?
    Many Thanks
    Jonathan

    Hi Jonathan
    we are having the same problem - did you find a way to resolve this?  I did not find any SAP notes referring to the issue.
    Regards
    Hayley

  • How to increase the length of the char which has master data!

    Hi,
    I am uploading hierarchy from flat file!
    i am using basic char texts as hierarchy texts  and my basic char has length  15 )
    Because the first 15 characters of the hierarchy short text are same, and it s total length being 15, while uploading it is giving me error saying same record values cannot be used more than once!
    ( i am using nodename as hierarchy texts  and my basic char has length  15 )
    when i try to increase the length of the char by deleting entries in it, the delete option is grayed out!
    Any suggestions?
    Thanks,
    Ravi

    Hi,
    Check it out that object where-used list, whether that object is used in any other cubes or ODS or any target......
    If it is used then delete all the data from all the targets and also object data itself.
    Then it is possible to increase the length.
    One more thing is if you want to change in Production system directly ,may be you have the display authorization only.
    You have to change it in to development system and trasport it to production system.
    Regards,
    Venkat

  • Changing animation frame rate when rendering in photoshop does not change the length of the video?

    I made a walk cycle animation in Photoshop CS6 and want to render it into a quicktime format. I'd like it to be 12 fps, but when I rendered it at 12 fps the video seemed to be missing frames, and the video was 3 seconds long. I have 98 frames to my animation; doing the math, at 12 fps it should be 8 seconds long. Not 3.
    I was confused and for curiosity's sake I rendered the video at 6 fps, trying to really slow it down. The video ended up being STILL 3 seconds long and only maybe 20 frames. I was missing literally 70 frames. I'm so upset with this rendering thing, I could chuck my computer at the wall.
    Does anybody know of a solution to this?
    edit: If it means anything, I've tried rendering it straight from the frame view and the timeline view. Each time I render it I have the timeline frame rate match the rendering frame rate as well.

    floriannaart wrote:
    Changing animation frame rate when rendering in photoshop does not change the length of the video?
    Photoshop CS6 and CC support two types of animation Frame animations and a Video Timeline
    Changing the frame rate should not change the length of a video timeline. It should just change the number of frames that are rendered.  To change the length of a video you need to change the length of the video timeline.  If you increase the length of the timeline and there is audio I'm quite sure there will be a problem with it,  The Video part will most likely be better then the sound. The required number of extra frames can be generated however the video may look like slow motion. If you decrease the length the motion will speed up.  The length of a video is normally done be editing video clips which are trimmed and stitched together to get the desired duration. Not normally done by altering the duration of a clip.
    The duration a of Frame animation is the sum of the times each frame is displayed.  In a frame animation the length of time a frame is displayed can be varied it not a normal motion picture video.  To have a smooth frame animation you need a sufficient number of frames that are different from each other to show smooth motion.  You can use Photoshop Frame animation tween feature to have Photoshop manufacture frames to help with a smoothing the animation.   Once you have a frame animation the length with the motion you want you can have Photoshop convert it to a video timeline and render a normal motion picture video.  It will not have audio but you can add audio to it.

  • What is the length of the Lightning cable that comes with the iPad Air?

    Actually have three questions.
    1. What is the length of the Lightning cable that came with my iPad Air? I ask because I might need to purchase a new one.
    2. My current Lightning cable, the one that came with my Air, the end of the cable, the rubber is coming off, it's stretched. Would AC+ send me a new one?
    3. I have an iPhone 5s also, does the iPhone have it's own unique Lightning cable or can I use my iPad Air Lightning cable to charge my iPhone and vice versa, are the Lightning cables universal with the newer products?
    Thanks.

    http://store.apple.com/us/ipad/ipad-accessories/cables-docks#!

  • If we can increase the length of the Short Text field in a purchase order?

    Hi Experts,
    Please suggest if we can increase the length of the Short Text field in a purchase order?
    If yes, How? and what will be the impact?
    Thanks
    Gavar

    Dear Arpit,
    You can use PO Text field for long description of the material.
    Regards,
    Manish Jain

Maybe you are looking for

  • URGENT: Error while creating a BAPI

    Hi all !! I am facing the below mentioned error while creating a BAPI , to be more specific , the error comes when i try adding a new method by using Utilities > API method > add a method on after adding a function modile name in there, when i click

  • Portlets and Primary Keys

    I'm just learning to use Portal. So I have this small employee database. I have three tables: Person, Location and Salary. The primary Key is person_id. I'm setting up the page so the the Person Table is displayed in a portlet at the top of the page

  • IDOC mapping 1 to 0..unbounded problem in PI 7.1

    All, We've recently implemented SAP PI 7.1 but we face an issue at the moment. Let me describe the case We have a Source message which is the DEBMAS IDOC. Within the IDOC we use mappings for Header data and for Detail Data. Mapping the header data is

  • How to capture hi8 super8?

    Hi, I have my Imac connect to a Dv converter what has S-video and composite. Now i would like to Be able to capture Super video, Video8 and Hi8. I don't know much about what play i have to get to work. Is there anyone who can tell me, if there is a u

  • DTD Creation using Java from XMLSchema

    Dear Friends Can anybody solve my problem.See friends i have the Schema With the help of that schema i want to create DTD Using Java .If u peoples have any solution please forward me sample code or tell me where i can get the information.