PDA

View Full Version : [JAVA]Creare guida


franksisca
13-09-2006, 16:14
Ragazzi, devo creare la guida del mio programmino, mi dite come posso fare???
mi hanno consigliato di usare un JDialog, e ho provato a fare questo:public class Guida
extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton chiudi = new JButton();
JScrollPane scroller = new JScrollPane();
JEditorPane html;

public Guida(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
//pack();
}
catch (Exception ex) {
ex.printStackTrace();
}
}

public Guida() {
this(null, "", false);
}

private void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
chiudi.setText("Chiudi");
this.setResizable(false);
this.setTitle("Guida");
this.setSize(600,500);
chiudi.addActionListener(new ActionListener(){
/**
* actionPerformed
*
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e) {
hide();
}
});
getContentPane().add(panel1);
try {
URL url = null;
// System.getProperty("user.dir") +
// System.getProperty("file.separator");
String path = null;
try {
path = "files/Guida.html";
url = getClass().getResource(path);
}
catch (Exception e) {
System.err.println("Failed to open " + path);
url = null;
}

if (url != null) {
html = new JEditorPane(url);
html.setEditable(false);
//html.addHyperlinkListener(createHyperLinkListener())
}
}
catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
}
catch (IOException e) {
System.out.println("IOException: " + e);
}

panel1.add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(chiudi, null);
panel1.add(scroller, BorderLayout.CENTER);
scroller.getViewport().add(html, null);
}
}

naturalmente alcune chiamate sono vecchie e deprecate, ma a me non fà vedere niente, mi spegate il motivo???

MEMon
13-09-2006, 16:39
Da qualche parte la rendi visibile?

spv42
13-09-2006, 17:00
Ragazzi, devo creare la guida del mio programmino, mi dite come posso fare???
mi hanno consigliato di usare un JDialog, e ho provato a fare questo:public class Guida
extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton chiudi = new JButton();
JScrollPane scroller = new JScrollPane();
JEditorPane html;

public Guida(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
//pack();
}
catch (Exception ex) {
ex.printStackTrace();
}
}

public Guida() {
this(null, "", false);
}

private void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
chiudi.setText("Chiudi");
this.setResizable(false);
this.setTitle("Guida");
this.setSize(600,500);
chiudi.addActionListener(new ActionListener(){
/**
* actionPerformed
*
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e) {
hide();
}
});
getContentPane().add(panel1);
try {
URL url = null;
// System.getProperty("user.dir") +
// System.getProperty("file.separator");
String path = null;
try {
path = "files/Guida.html";
url = getClass().getResource(path);
}
catch (Exception e) {
System.err.println("Failed to open " + path);
url = null;
}

if (url != null) {
html = new JEditorPane(url);
html.setEditable(false);
//html.addHyperlinkListener(createHyperLinkListener())
}
}
catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
}
catch (IOException e) {
System.out.println("IOException: " + e);
}

panel1.add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(chiudi, null);
panel1.add(scroller, BorderLayout.CENTER);
scroller.getViewport().add(html, null);
}
}

naturalmente alcune chiamate sono vecchie e deprecate, ma a me non fà vedere niente, mi spegate il motivo???


devi fare uno show() ed un pack();

franksisca
13-09-2006, 17:23
la rendo visibile dopo, quando la chiamo naturalmente, mentre il pack non l'ho fatto.


appena posso provo, ma il motivo del pack???
sò cosa fà, ma perchè in questo caso dovrebbe rendermi il tutto visibile????

magari mi sfugge qualcosa del pack:D

MEMon
13-09-2006, 17:58
Ok visto che l'ipotesi più banale non era, ha ragione spv42, ti manca il pack() :D

Siccome non dai una dimensione al frame devi utilizzare il pack per dargli automaticamente la dimensione minima per contenere i componenti.
Altrimenti la dimensione è 0,0

franksisca
13-09-2006, 19:54
mmm, diciamo che se ricordo bene il problema non è quello, comunque testo e vi faccio sapere, al massimo domani.

MEMon
13-09-2006, 19:56
Bhe quello è un problema poi magari ce ne sono altri...