Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PPJ_28;
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Paint;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.io.*;
- import java.util.StringTokenizer;
- public class PPJ28_1 extends Frame {
- static Color tab[][] ;
- public static void main(String[] args) {
- File file = new File("D:\\Snow .ppm");
- FileReader fis = null ;
- StringBuffer sb = new StringBuffer();
- try {
- fis = new FileReader(file);
- int tmp;
- while ( (tmp = fis.read())!=-1) {
- sb.append((char)tmp);
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }catch(IOException e){
- e.printStackTrace();
- }
- String text = sb.toString();
- StringTokenizer st = new StringTokenizer(text);
- st.nextToken();
- st.nextToken();
- st.nextToken();
- st.nextToken();
- st.nextToken();
- int a = Integer.parseInt(st.nextToken());
- int c = Integer.parseInt(st.nextToken());
- tab = new Color[c][a];
- st.nextToken();
- for (int i = 0; i < tab.length; i++) {
- for (int j = 0; j < tab[i].length; j++) {
- int r = Integer.parseInt(st.nextToken());
- int g =Integer.parseInt(st.nextToken());
- int b = Integer.parseInt(st.nextToken());
- tab[i][j] = new Color(r, g,b );
- }
- }
- new PPJ28_1();
- }
- public PPJ28_1() {
- setSize( 700, 700);
- setVisible(true);
- addWindowListener(
- new WindowAdapter(){
- public void windowClosing(WindowEvent evt){
- System.exit(0);
- }
- }
- );
- }
- public void paint(Graphics g){
- for(int i=0; i<tab.length; i++){
- for(int j=0; j<tab[i].length; j++){
- g.setColor(tab[i][tab[i].length-j-1]);
- g.drawLine( 50 + j, 50 + i, 50 + j, 50 + i);
- }
- }
- for(int i=tab.length-1; i>0; i--){
- for(int j=tab[i].length-1; j>0; j--){
- g.setColor(tab[i][j]);
- g.drawLine( 540 + j, 50 + i, 540 + j, 50 + i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement