JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 java load image 沒辦法更新問題
howay0516





發文: 1
積分: 0
於 2007-04-10 14:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
抱歉我吧整段code貼上來

我目前用java.awt 將圖片load近來

我這段程式的功能是用滑鼠滾輪切換圖片

目前已經可以做到偵測到滑鼠滾輪

切換圖片的部分有個bug

就是我滑鼠假設我滾了一格 我設計上是要由example1.jpg 切換到 example2.jpg

但在視窗中(textArea)中圖不會改變 不過如果移動視窗或是改變視窗大小

圖就會變成我想要的(例:滑鼠滾輪動一格 圖片不會變 但改變視窗大小後

圖就變成example2.jpg了)

我在想說是不是我的Show_off_test中 改變圖片時 沒有辦法及時flush??

我用的OS是vista-32bit 會不會是OS的問題= =詭異的bug 大家幫幫我吧 謝謝

public class MouseWheelEventDemo extends JPanel
implements MouseWheelListener {
JTextArea textArea;
JScrollPane scrollPane;
final static String newline = "\n";
private static ImageDelegate mImage;
static JFrame frame = new JFrame("Project 2007.4.7");
static Graphics g;
static String[] names = {"example1.jpg","example2.jpg","example3.jpg","example4.jpg","example5.jpg"};
int count = 0;
public MouseWheelEventDemo() {
super(new BorderLayout());

textArea = new JTextArea();
textArea.setEditable(false);
scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setSize( new Dimension (1024,768));
add(scrollPane, BorderLayout.CENTER);

//Register for mouse-wheel events on the text area.
textArea.addMouseWheelListener(this);


setPreferredSize(new Dimension(1024, 768));
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

public void mouseWheelMoved(MouseWheelEvent e){
// String message;


int notches = e.getWheelRotation();

if (notches == -1){
   count--;
}
else{
   count++;
}
if( count > 4 )
   count = 0;
else if( count < 0)
   count = 4;

ShowOff_test( names[ count ]);
System.out.println("TEST: " + names[ count ]);



}

  public void paint( Graphics g ) {
    
    Graphics2D g2 = (Graphics2D)g;

    // Turn on antialiasing.
    g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    g2.drawImage( MouseWheelEventDemo.mImage.getImage(), 0, 0, null );
    //frame.dispose();
//g2.dispose();
  }

  public static void ShowOff_test( String filename) {
    

  try {
  final Image image = ImageIO.read( new File( filename ) );
  mImage = (
    new ImageDelegate() {
    public Image getImage() { return image; }
        }
      
      Wink;
    
//this.setSize( mImage.getWidth( null ), mImage.getHeight( null ) );
    } catch ( Exception _ ) {
      throw new RuntimeException( _ );
    }

  }
  

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
  
//Create and set up the window.

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
JComponent newContentPane = new MouseWheelEventDemo();
newContentPane.setOpaque(false); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
//frame.update(mImage.getGraphics());
frame.dispose();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
  
  ShowOff_test( names[ 0 ]);

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2228 java load image 沒辦法更新問題 howay0516 4552 2007-04-10 14:58
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8