PDA

View Full Version : [JAVA] Aiuto ragazzi con questo programma...


Sartan
06-11-2006, 11:52
Dunque ragazzi, devo trasformare questo programma in un'applet java per un progetto scolastico.
Il problema sorge gia dalla compilazione del programma cosi' come mi e' stato consegnato, in quanto non trova il package com.borland.jdbc.layout.XYlayout e com.borland.jdbc.layout.XYconstraint. Ho controllato su intenert e questi due package sono inglobati in jbuilder della borland... ho provato pure jbuilder ma sti package nn me li trova -_-.

Sapreste come aiutarmi???

Eccovi il sorgente...

package teoremacolori1;

import com.borland.jbcl.layout.XYConstraints;
import com.borland.jbcl.layout.XYLayout;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;

public class TC1 extends JFrame
{
public class Retta
{

public int C;
public int X;
public int Y;

public Retta(int CX, int CY, int CC)
{
X = CX;
Y = CY;
C = CC;
}
}


public TC1()
{
PointMatrix = new int[600][600];
X0 = 10;
Y0 = 50;
Rette = new Vector();
MainPanel = new JPanel();
lblInsRetta = new JLabel("Inserimento retta");
txtRX1 = new JTextField("0");
txtRY1 = new JTextField("0");
txtRX2 = new JTextField("0");
txtRY2 = new JTextField("0");
lblRX1 = new JLabel("X1:");
lblRY1 = new JLabel("Y1:");
lblRX2 = new JLabel("X2:");
lblRY2 = new JLabel("Y2:");
btnInsRetta = new JButton("Abilita inserimento retta");
btnReset = new JButton("Reset");
init();
break MISSING_BLOCK_LABEL_212;
Exception e;
e;
e.printStackTrace();
return;
}

private void InsRettaButtonActionPerformed(ActionEvent evt)
{
if(FlagInserimentoRetta == 0)
{
FlagInserimentoRetta = 1;
txtRX1.setEditable(true);
txtRY1.setEditable(true);
txtRX2.setEditable(true);
txtRY2.setEditable(true);
btnInsRetta.setLabel("Inserisci retta");
} else
{
int CX1;
if(txtRX1.getText().compareTo("") == 0)
CX1 = 0;
else
CX1 = Integer.parseInt(txtRX1.getText());
int CY1;
if(txtRY1.getText().compareTo("") == 0)
CY1 = 0;
else
CY1 = Integer.parseInt(txtRY1.getText());
int CX2;
if(txtRX2.getText().compareTo("") == 0)
CX2 = 0;
else
CX2 = Integer.parseInt(txtRX2.getText());
int CY2;
if(txtRY2.getText().compareTo("") == 0)
CY2 = 0;
else
CY2 = Integer.parseInt(txtRY2.getText());
if((CX1 == CX2) & (CY1 == CY2))
return;
int A = CY2 - CY1;
int B = CX1 - CX2;
int C = CX2 * CY1 - CX1 * CY2;
Retta NewRetta = new Retta(A, B, C);
Rette.addElement(NewRetta);
for(int i = 0; i < 600; i++)
{
for(int k = 1; k < 601; k++)
{
int P = i * NewRetta.X + k * NewRetta.Y + NewRetta.C;
if(P == 0)
PointMatrix[i][600 - k] = 0;
if(P < 0)
{
if(PointMatrix[i][600 - k] != 2);
if(PointMatrix[i][600 - k] == 0)
PointMatrix[i][600 - k] = 1;
else
if(PointMatrix[i][600 - k] == 1)
PointMatrix[i][600 - k] = 0;
}
}

}

FlagInserimentoRetta = 0;
txtRX1.setEditable(false);
txtRY1.setEditable(false);
txtRX2.setEditable(false);
txtRY2.setEditable(false);
btnInsRetta.setLabel("Abilita inserimento retta");
repaint();
}
}

private void ResetButtonActionPerformed(ActionEvent evt)
{
txtRX1.setEditable(false);
txtRY1.setEditable(false);
txtRX2.setEditable(false);
txtRY2.setEditable(false);
FlagInserimentoRetta = 0;
for(int i = 0; i < 600; i++)
{
for(int k = 0; k < 600; k++)
PointMatrix[i][k] = 0;

}

repaint();
}

public void drawGrid(Graphics g)
{
g.setColor(Color.white);
g.drawRect(X0, Y0, 600, 600);
g.setColor(Color.black);
g.fillRect(X0, Y0, 600, 600);
}

public void init()
{
XYLayout Layout = new XYLayout();
MainPanel = (JPanel)getContentPane();
MainPanel.setLayout(Layout);
MainPanel.add(lblInsRetta, new XYConstraints(620, 60, 150, 20));
MainPanel.add(lblRX1, new XYConstraints(620, 90, 20, 20));
MainPanel.add(lblRY1, new XYConstraints(715, 90, 20, 20));
MainPanel.add(lblRX2, new XYConstraints(620, 120, 20, 20));
MainPanel.add(lblRY2, new XYConstraints(715, 120, 20, 20));
MainPanel.add(txtRX1, new XYConstraints(645, 90, 30, 20));
MainPanel.add(txtRY1, new XYConstraints(740, 90, 30, 20));
MainPanel.add(txtRX2, new XYConstraints(645, 120, 30, 20));
MainPanel.add(txtRY2, new XYConstraints(740, 120, 30, 20));
MainPanel.add(btnInsRetta, new XYConstraints(620, 160, 180, 20));
MainPanel.add(btnReset, new XYConstraints(620, 550, 130, 20));
btnInsRetta.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt)
{
InsRettaButtonActionPerformed(evt);
}

});
btnReset.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt)
{
ResetButtonActionPerformed(evt);
}

});
txtRX1.setEditable(false);
txtRY1.setEditable(false);
txtRX2.setEditable(false);
txtRY2.setEditable(false);
setLocation(50, 20);
setResizable(false);
setSize(new Dimension(850, 700));
setTitle("Problema dei 2 colori: Teorema 1");
setVisible(true);
setDefaultCloseOperation(2);
enableEvents(80L);
FlagInserimentoRetta = 0;
for(int i = 0; i < 600; i++)
{
for(int k = 0; k < 600; k++)
PointMatrix[i][k] = 0;

}

}

public static void main(String args[])
{
TC1 T = new TC1();
}

public void paint(Graphics g)
{
drawGrid(g);
lblInsRetta.repaint();
lblRX1.repaint();
lblRY1.repaint();
lblRX2.repaint();
lblRY2.repaint();
txtRX1.repaint();
txtRY1.repaint();
txtRX2.repaint();
txtRY2.repaint();
btnInsRetta.repaint();
btnReset.repaint();
for(int i = 0; i < 600; i++)
{
for(int k = 0; k < 600; k++)
{
if(PointMatrix[i][k] == 0)
{
g.setColor(Color.black);
g.fillRect(X0 + i, Y0 + k, 1, 1);
}
if(PointMatrix[i][k] == 1)
{
g.setColor(Color.gray);
g.fillRect(X0 + i, Y0 + k, 1, 1);
}
if(PointMatrix[i][k] == 2)
{
g.setColor(Color.white);
g.fillRect(X0 + i, Y0 + k, 1, 1);
}
}

}

}

protected void processMouseEvent(MouseEvent e)
{
if(e.getID() == 501)
{
int Flag = 0;
int CurX = e.getX();
int CurY = e.getY();
if((CurX > -1) & (CurX < 601) & (CurY > -1) & (CurY < 601))
{
if(FlagInserimentoRetta == 2)
{
txtRX2.setText(String.valueOf(CurX));
txtRY2.setText(String.valueOf(600 - CurY));
FlagInserimentoRetta = 3;
}
if(FlagInserimentoRetta == 1)
{
txtRX1.setText(String.valueOf(CurX));
txtRY1.setText(String.valueOf(600 - CurY));
FlagInserimentoRetta = 2;
}
}
super.processMouseEvent(e);
}
}

protected void processWindowEvent(WindowEvent e)
{
if(e.getID() == 201)
{
dispose();
System.exit(0);
}
super.processWindowEvent(e);
}

int FlagInserimentoRetta;
JPanel MainPanel;
int PointMatrix[][];
Vector Rette;
int X0;
int Y0;
JButton btnInsRetta;
JButton btnReset;
JLabel lblInsRetta;
JLabel lblRX1;
JLabel lblRX2;
JLabel lblRY1;
JLabel lblRY2;
JTextField txtRX1;
JTextField txtRX2;
JTextField txtRY1;
JTextField txtRY2;


}

Grazie di tutto...

Bonfo
06-11-2006, 12:17
Dunque ragazzi, devo trasformare questo programma in un'applet java per un progetto scolastico.
Il problema sorge gia dalla compilazione del programma cosi' come mi e' stato consegnato, in quanto non trova il package com.borland.jdbc.layout.XYlayout e com.borland.jdbc.layout.XYconstraint. Ho controllato su intenert e questi due package sono inglobati in jbuilder della borland... ho provato pure jbuilder ma sti package nn me li trova -_-.

Sapreste come aiutarmi???

Eccovi il sorgente...

[CUT]

Grazie di tutto...


Per avere la risposta migliore chiama il tuo professore e digli che tu JBuilder non lo hai.
Se lui ti risponde "allora??" tu hai 2 possibilta':
- lo denunci perche' e' un ignorante
- gli chiedi se ha una versione che non usi i package di JBuilder ma quello standard dell'SDK

EDIT: ho visto adesso il programma :stordita: forse basta che cancelli i due import ;)

Sartan
06-11-2006, 12:33
Ho sistemato la questione dell'import del package Jcbl..

Ora mi rimane la questione piu importante...

Come trasformo questa applicazione stand alone, in un'applet??