可以說我有:得到局部變量值類變量
class BlaBla{
int x;
int y;
public void actionPerformed(ActionEvent e){
int m1;
int m2;
// algorhythm where i get values for m1 and m2
}
}
我該怎麼分配的m1
值x
和m2
到y
?
因爲我想在另一個類中使用m1
和m2
的值?在另一個類中,我有繪畫方法,我想用它們作爲繪畫的座標。
謝謝
我的動作按鈕將解析XML文件。比我更需要塗料的方法,這是在其他類四個變量
public void actionPerformed(ActionEvent e){
try{
JFileChooser fch = new JFileChooser();
int i = fch.showOpenDialog(null);
if(i==JFileChooser.APPROVE_OPTION){
File f = fch.getSelectedFile();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(f);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("line");
// NodeList nList = doc.getElementsByTagName("point");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
Element line = (Element) nList.item(0);
Element point1 = (Element) line.getElementsByTagName("point").item(0);
Element point2 = (Element) line.getElementsByTagName("point").item(1);
int m1 = Integer.parseInt(point1.getElementsByTagName("X").item(0).getTextContent());
int n1 = Integer.parseInt(point1.getElementsByTagName("Y").item(0).getTextContent());
int m2 = Integer.parseInt(point2.getElementsByTagName("X").item(0).getTextContent());
int n2 = Integer.parseInt(point2.getElementsByTagName("Y").item(0).getTextContent());
我的主類是:
public class Line {
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setTitle("Test");
frame.setLayout(new FlowLayout());
final JPanel pnl = new JPanel(){
public void paintComponent(Graphics g){
super.paintComponent(g);
Vyber v = new Vyber();
g.drawLine(x1, y1, x2, y2); //values from method from another class
}
實現getter和setter的東西。 – Maroun
@HovercraftFullOfEels我編輯我的問題並添加更多信息 – DRastislav