可以说我有:
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
tox
和m2
to的值y
?
因为我想在另一个类中使用m1
and的值?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
}