代码如下
Tombol tombolIkonJelajahi;
Tombol tombolSetIkon;
Ikon cangkang gambar;
Tombol gambarIkon;
publik IconSelector() {
inisialisasiUI();
shell.paket();
shell.open();
while (!shell.isDisposition()) {
if (!display.readAndDispatch()) {
tampilan.tidur();
}
}
tampilan.buang();
}
kekosongan pribadi inisialisasiUI() {
GridLayout gridLayout = GridLayout baru(3, salah);
shell.setLayout(gridLayout);
labelIconFile = Label baru(kulit, SWT.NULL);
textIconFile = Teks baru (shell, SWT.SINGLE | SWT.BORDER);
GridData gridData = GridData baru(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = benar;
textIconFile.setLayoutData(gridData);
buttonIconBrowse = Tombol baru(shell, SWT.PUSH);
gridData = GridData baru();
gridData.horizontalSpan = 3;
gridData.horizontalAlignment = GridData.CENTER;
buttonSetIcon = Tombol baru(shell, SWT.PUSH);
buttonSetIcon.setLayoutData(gridData);
shell.setText("Pemilih Ikon");
labelIconFile.setText("Pilih ikon:");
buttonIconBrowse.setText("Jelajahi");
buttonSetIcon.setText("Set Ikon");
buttonIconBrowse.addSelectionListener(SelectionAdapter baru() {
widget kekosongan publikDipilih(SelectionEvent e) {
Dialog FileDialog = FileDialog baru(shell, SWT.OPEN);
File string = dialog.open();
jika (berkas != nol) {
textIconFile.setText(file);
}
}
});
buttonSetIcon.addSelectionListener(SeleksiAdapter baru() {
widget kekosongan publikDipilih(SelectionEvent e) {
jika(Ikon cangkang!= nol)
shellIcon.buang();
mencoba {
shellIcon = Gambar baru(tampilan, textIconFile.getText());
shell.setImage(shellIcon);
}menangkap(Pengecualian ex) {
ex.printStackTrace();
}
}
});
}
public static void main(String[] args) {
IconSelector baru();
}
}