简体   繁体   中英

What`s wrong with it? jform application

I am creating an app that runs a file if user has provided correct login and password in netbeans.

import java.io.File;
import java.io.IOException;
import java.awt.*;
import java.lang.Runtime;
import java.awt.Desktop;
import static java.awt.SystemColor.desktop;
import java.io.File;
 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
if(Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
}
if(desktop.isSupported(Desktop.Action.OPEN)){
    desktop.open(new File("C:\\Users\\user\\Desktop\\asd.png"));
}
jTextField1.setText(" ");     
jTextField2.setText(" ");    
    }             

It is showing an error in -

 if(desktop.**isSupported**(Desktop.Action.OPEN)){
    desktop.**open**(new File("C:\\Users\\user\\Desktop\\asd.png"));

COMPILATION ERROR : 
-------------------------------------------------------------
NewJFrame.java:[130,11] cannot find symbol
  symbol:   method isSupported(java.awt.Desktop.Action)
  location: variable desktop of type java.awt.SystemColor
NewJFrame.java:[131,12] cannot find symbol
  symbol:   method open(java.io.File)
  location: variable desktop of type java.awt.SystemColor
2 errors 
------------------------------

You have created a variable Desktop desktop . You also have a static import java.awt.SystemColor.desktop . static import desktop has precedence over variable desktop. Open method is not available in java.awt.SystemColor.desktop. It is available in java.awt.Desktop. You should rename your variable desktop to awtDesktop or something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM