我能这样做吗?我想设置我的选项窗格的默认值是9090 ..这是我的选项窗格代码
private static int setPortNumber()
{
String portNumber = JOptionPane.showInputDialog(frame,
"Enter the Port number for server creation","Server Connection\n",
JOptionPane.OK_CANCEL_OPTION);
int PORT = Integer.parseInt(portNumber);
return PORT;
}
Run Code Online (Sandbox Code Playgroud) 我有一个gui服务器,首先调用joptionpanel输入端口号.如果我单击OK按钮,它看起来运行良好.但是如果在第一次运行中我单击取消,然后单击确定我的GUI冻结.我觉得上课start()让它冻结了.
对不起,这是一个重复的问题,但也许问题与其他问题不同.
这是我的服务器代码.任何人都可以帮助我.是什么导致gui冻结?
public class server {
// Main meathod
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Throwable e) {
e.printStackTrace();
}
server server2 = new server(PORT);
server2.start();
}
public server(int PORT)
{
sdf = new SimpleDateFormat("[HH:mm:ss]");
go();
}
public void go() {
//The GUI hidden`enter code here`...
connect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// When Exit button is pressed
if (ae.getSource() == connect) {
start();
}
}
});
}
// …Run Code Online (Sandbox Code Playgroud) 我在下面有这个代码.它在Activity之前有效.现在我想将它转换为Fragment.我尝试过context.getContentResolver(); 或getActivity().getContentResolver(); 但它不起作用.如何解决这个问题?
public class MyFragmentA extends Fragment {
//song list variables
private ArrayList<Song> songList;
private ListView songView;
public Context context;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.fragment_a, container, false);
//retrieve list view
songView = (ListView) myFragmentView.findViewById(R.id.song_list);
//instantiate list
songList = new ArrayList<Song>();
//get songs from device
getSongList();
//sort alphabetically by title
Collections.sort(songList, new Comparator<Song>(){
public int compare(Song a, Song b){
return a.getTitle().compareTo(b.getTitle());
}
});
//create and set adapter
SongAdapter songAdt …Run Code Online (Sandbox Code Playgroud)