Hi guys
I will be very appreciate if somebody could tell me what is wrong with my code? Namely I am trying to develop a simple applet that has button "Load" to load set of points specified by x,y coordinates from a file and display these point in applet window. I store these point as ListArray everything seems to working fine apart displaying these point in window as specified by its coordinates. Could anybody help me with this issue, thanks in advance and the code is a below:
P.s I only attached the part of the code, If anybody can only suggest to load these values on display it on screen
public class Project extends JApplet implements ActionListener { private JPanel contentPane; private JPanel buttonPane; private JButton load; private RectangleArea rectangleArea; private PointSet pointSet = new PointSet(); private Point pTemp = null; private boolean showMax = false; //This is my code to load data from data.txt public Project() { init(); try { ArrayList<Integer> column1 = new ArrayList<Integer>(); // Defining an integer Array List ArrayList<Integer> column2 = new ArrayList<Integer>(); // Defining an integer Array List Scanner myfile = new Scanner(new FileReader("E:\\app\\data.txt")); // Reading file using Scanner while (myfile.hasNext()) { // Read file content using a while loop column1.add(myfile.nextInt()); // Store the first integer into the first array list column2.add(myfile.nextInt()); // Store the next integer into the second array list } System.out.println("column 1 elements are:\n" + column1); System.out.println("column 2 elements are:\n" + column2); myfile.close(); // close the file }catch (Exception e) { e.printStackTrace(); } } public void init() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); contentPane = (JPanel) this.getContentPane(); buttonPane = new JPanel(); contentPane.setLayout(new BorderLayout()); GridLayout buttonLayout = new GridLayout(0,9); buttonPane.setLayout(buttonLayout); buttonPane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); random = new JButton("Load"); load.addActionListener(this); load.setToolTipText("Display data"); buttonPane.add(Box.createHorizontalStrut(10)); buttonPane.add(new JLabel("",SwingConstants.CENTER)); buttonPane.add(new JLabel("",SwingConstants.CENTER)); buttonPane.add(load); buttonPane.add(new JLabel("",SwingConstants.CENTER)); buttonPane.setAlignmentX(CENTER_ALIGNMENT); rectangleArea = new RectangleArea(this); MouseListener listener = new MouseListener(this); rectangleArea.addMouseListener(listener); rectangleArea.setAlignmentX(LEFT_ALIGNMENT); contentPane.add(rectangleArea,BorderLayout.CENTER); contentPane.add(buttonPane,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e){ if (e.getSource() == load) { //isOK=true; pointSet.clear(); //[B]I can set a single point //But how to load these values from my txt fille [/B] Point p = new Point(); p.setX(44); p.setY(22); pointSet.addPoint(p); this.addPoint(p); this.setPTemp(p); } getRectangleArea().repaint(); } public void addPoint(Point p) { this.pointSet.addPoint(p); } public PointSet getPointSet() { return pointSet; } public void setPointSet(PointSet pointSet) { this.pointSet = pointSet; } public JButton getMaxD() { return maxD; } public void setMaxD(JButton maxD) { this.maxD = maxD; } public boolean isShowMax() { return showMax; } public void setShowMax(boolean showMax) { this.showMax = showMax; } public Point getPTemp() { return pTemp; } public void setPTemp(Point temp) { pTemp = temp; } public RectangleArea getRectangleArea() { return rectangleArea; } public void setRectangleArea(RectangleArea rectangleArea) { this.rectangleArea = rectangleArea; } }