A
AkeL.php
Guest
Ответ: Java.Help
Делаю:
PHP:
import java.util.Vector;
import java.util.Scanner;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class graf extends JPanel{
public static int N = 4, M=3;
public static int[][] g= new int[N][M];
public static Vector<Integer> gr = new Vector<Integer>();
public static Line2D.Double line = new Line2D.Double(20, 20, 20, 150);
static void read(String filename) throws Exception{
int i,j;
System.out.println("Считывание " + filename);
try{
Scanner sc = new Scanner(new File(filename));
for (i=0; i<N; i++){
for (j=0; j<M; j++){
g[i][j] = sc.nextInt();
System.out.print(" " + g[i][j]);
}
System.out.println();
}
}
catch(Exception e){}
}
static void solve(){
int i,j,w,s,min = 666, next=0;
for (i=0; i<N; i++){
w = g[i][0];
s = g[i][1];
if ((gr.contains(w))&&(!gr.contains(s))){
for (j=0; j<gr.size(); j++){
if (g[i][2] <= min){
min = g[i][2];
next = g[i][1];
}
}
System.out.println(g[i][0] +"->" + next);
gr.add(next);
min=666;
}
}
}
public void paintComponent(Graphics g){
gr.add(1);
read("f.txt");
solve();
Graphics2D g2d = (Graphics2D)g;
g2d.draw(line);
}
public static void main(String[] args) {
WindowUtilities.openInJFrame(new graf(), 640, 480);
}
}
HTML:
graf.java:51: unreported exception java.lang.Exception; must be caught or declared to be thrown
read("f.txt");
^
1 error
PHP:
public void paintComponent(Graphics g) throws Exception{
gr.add(1);
read("f.txt");
solve();
Graphics2D g2d = (Graphics2D)g;
g2d.draw(line);
}
HTML:
graf.java:48: paintComponent(java.awt.Graphics) in graf cannot override paintComponent(java.awt.Graphics) in javax.swing.JComponent; overridden method does not throw java.lang.Exception
public void paintComponent(Graphics g) throws Exception{
^
1 error