Hallo liebe Gemeinde der Java-Programmierung. Ich habe ein perverses Problem mit meiner Anwendung die ich entwickelt habe und die ich nächsten dienstag präsentieren soll.
Ich habe ein anwendung entwickelt die ein soziales Netzwerk visualisiert.
Ich habe neben einem suchfeld eine Progrssbar in die Gui eingebaut die je nach Stand des Crawlvorganges im Netzwerk gesetzt wird. Beim Crawlvorgnag werden XML-Dateien geöffenet und genau zu dem Zeitpunkt friert mir die Anwendung ein.
hier mein Code in der Klasse GUI:
Dann habe ich eine Methode getUserProfile die ausgeführt wid sobald ich etwas ins Suchfeld eingebe:
Genau hier in dem Code will ich die Werte in der Progrssbar setzen, das macht er zwar aber zeigt es nicht an, erst wenn alle Profile und connections abgearbeitet wurden
hier noch als Zusatz mein Eingabefeld, vielleicht hängts daran:
Ich sitze jetzt schon seit einer Woche an dem Problem und ich finde es einfach nicht..... bitte helft mir
Ich habe ein anwendung entwickelt die ein soziales Netzwerk visualisiert.
Ich habe neben einem suchfeld eine Progrssbar in die Gui eingebaut die je nach Stand des Crawlvorganges im Netzwerk gesetzt wird. Beim Crawlvorgnag werden XML-Dateien geöffenet und genau zu dem Zeitpunkt friert mir die Anwendung ein.
hier mein Code in der Klasse GUI:
Code:
public static JPanel getProgressBar() {
progressPanel = new JPanel();
//progressPanel.setPreferredSize(new Dimension(20, 20));
progressPanel.setLayout(new GridLayout(2, 2));
progressPanel.setSize(140, 45);
progressPanel.setVisible(true);
progressPanel.setBackground(Color.WHITE);
//progressPanel.setBounds( 480, 1, 270, 43 );
//progressPanel.setBorder(BorderFactory.createTitledBorder("Status"));
jLabelstatus = new JLabel();
jLabelstatus.setText("Status: ");
jLabelstatus.setBackground(Color.WHITE);
//Configure StatusBar-Panel
progressBar = new JProgressBar(0, 100);
progressBar.setStringPainted(true);
progressBar.setVisible(true);
progressBar.setSize(120,20);
progressBar.setBackground(Color.white);
progressPanel.add(jLabelstatus);
progressPanel.add(progressBar);
return progressPanel;
}
public static void addButtons(JToolBar jtb) {
//Zoom Out
tbBzo = new JButton();
tbBzo.setToolTipText("Zoom Out");
tbBzo.setBounds( 20, 1, 56, 42 );
tbBzo.setOpaque(true);
tbBzo.setVisible(false);
tbBzo.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/zo.jpg")));
tbBzo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Zoom OUT");
getTreeDisplay().zoomOut();
getGraphPanel().zoomOut();
}
});
jtb.add(tbBzo);
.
.
.
//Background left
iconleft = new ImageIcon((ClassLoader.getSystemResource("images/tbbgleft.jpg")));
jLabelIconleft = new JLabel(iconleft);
jLabelIconleft.setBounds( 0, 1, 208, 42 );
jLabelIconleft.setOpaque(true);
jtb.add(jLabelIconleft);
//Background right
iconright = new ImageIcon(ClassLoader.getSystemResource("images/tbbgright.jpg"));
jLabelIconright = new JLabel(iconright);
jLabelIconright.setBounds( 478, 1, 522, 42 );
jLabelIconright.setOpaque(true);
jLabelIconright.add(getProgressBar());
jtb.add(jLabelIconright);
}
private static JToolBar getJToolbar() {
if (tb == null) {
tb = new JToolBar ();
tb.setLayout(null);
tb.setPreferredSize( new Dimension(1000, 44) ); //(breite, hšhe)
tb.setFloatable(false);
tb.add(getSearchfield());
//tb.add(getProgressBar());
addButtons(tb);
}
return tb;
}
Dann habe ich eine Methode getUserProfile die ausgeführt wid sobald ich etwas ins Suchfeld eingebe:
Code:
public static void getUserProfile(String username) {
try {
/**
* Connection to given User
* Parsing XML-File into DOM Tree
* Reading Tags und Attributes of this file
*
*/
URL url = new URL("http://......../user/"+ username + "/profile.xml");
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
Document document = null;
try {
Gui.getBalken().setValue(24);
// Starts parsing the user xml file
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(is);
System.out.println("Datei existiert ");
hier noch als Zusatz mein Eingabefeld, vielleicht hängts daran:
Code:
public class Searchfield extends JTextField {
private static final long serialVersionUID = 1L;
private static final CancelBorder CANCEL_BORDER = new CancelBorder();
private boolean sendsNotificationForEachKeystroke = false;
private boolean showingPlaceholderText = false;
private boolean armed = false;
public Searchfield(String placeholderText) {
super(15);
addFocusListener(new PlaceholderText(placeholderText));
initBorder();
initKeyListener();
}
public Searchfield() {
this("look for username");
}
//Set Border
private void initBorder() {
setBorder(new CompoundBorder(getBorder(), CANCEL_BORDER));
MouseInputListener mouseInputListener = new CancelListener();
addMouseListener(mouseInputListener);
addMouseMotionListener(mouseInputListener);
}
private void initKeyListener() {
addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
cancel();
} else if (sendsNotificationForEachKeystroke) {
maybeNotify();
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
Gui.tbBzi.setVisible(true);
Gui.tbBzo.setVisible(true);
Gui.tbBzf.setVisible(true);
Profile.webButton.setEnabled(true);
Gui.tpcontent.remove( Gui.getJPanel_intro() );
ActionEventHandler.performSearch();
}
}
});
}
private void cancel() {
setText("");
postActionEvent();
}
private void maybeNotify() {
if (showingPlaceholderText) {
return;
}
postActionEvent();
}
public void setSendsNotificationForEachKeystroke(boolean eachKeystroke) {
this.sendsNotificationForEachKeystroke = eachKeystroke;
}
/**
* Draws the cancel button as a gray circle with a white cross inside.
*/
static class CancelBorder extends EmptyBorder {
private static final long serialVersionUID = 1L;
private static final Color GRAY = new Color(0.7f, 0.7f, 0.7f);
CancelBorder() {
super(0, 0, 0, 15);
}
public void paintBorder(Component c, Graphics oldGraphics, int x, int y, int width, int height) {
Searchfield field = (Searchfield) c;
if (field.showingPlaceholderText || field.getText().length() == 0) {
return;
}
Graphics2D g = (Graphics2D) oldGraphics;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final int circleL = 14;
final int circleX = x + width - circleL;
final int circleY = y + (height - 1 - circleL)/2;
g.setColor(field.armed ? Color.GRAY : GRAY);
g.fillOval(circleX, circleY, circleL, circleL);
final int lineL = circleL - 8;
final int lineX = circleX + 4;
final int lineY = circleY + 4;
g.setColor(Color.WHITE);
g.drawLine(lineX, lineY, lineX + lineL, lineY + lineL);
g.drawLine(lineX, lineY + lineL, lineX + lineL, lineY);
}
}
/**
* Handles a click on the cancel button by clearing the text and notifying
* any ActionListeners.
*/
class CancelListener extends MouseInputAdapter {
private boolean isOverButton(MouseEvent e) {
// If the button is down, we might be outside the component
// without having had mouseExited invoked.
if (contains(e.getPoint()) == false) {
return false;
}
// In lieu of proper hit-testing for the circle, check that
// the mouse is somewhere in the border.
Rectangle innerArea = SwingUtilities.calculateInnerArea(Searchfield.this, null);
return (innerArea.contains(e.getPoint()) == false);
}
/**
* Replaces the entered text with a gray placeholder string when the
* search field doesn't have the focus. The entered text returns when
* we get the focus back.
*/
class PlaceholderText implements FocusListener {
private String placeholderText;
private String previousText = "";
private Color previousColor;
PlaceholderText(String placeholderText) {
this.placeholderText = placeholderText;
focusLost(null);
}
public void focusGained(FocusEvent e) {
setForeground(previousColor);
setText(previousText);
showingPlaceholderText = false;
}
public void focusLost(FocusEvent e) {
previousText = getText();
previousColor = getForeground();
if (previousText.length() == 0) {
showingPlaceholderText = true;
setForeground(Color.GRAY);
setText(placeholderText);
}
}
}
}
Ich sitze jetzt schon seit einer Woche an dem Problem und ich finde es einfach nicht..... bitte helft mir