Making a diagram interactive???


Hi @ll,

I'm programming a complicated Applet with a lot of functions. Because of just a bit experiences with java several problems occure.
I'm showing a graph with the paint(Graphics g) Method. Thats why I paint the graph with g.drawPolyline(...) . Now I would like to
know, if there is any possibility to add a Listener, because I would like to show the exact values in a textfield, after the user clicked
the graph.

bye

Constanze
Posted On: Tuesday 23rd of October 2012 10:54:28 PM Total Views:  61
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Problems on making desktop application using java

how do i make a desktop application when org.jdesktopapplication package doesnt exist. i already checked my libraries. the specific swing library is inexistent
VIEWS ON THIS POST

126

Posted on:

Saturday 22nd September 2012
View Replies!

Wants to learn making of desktop applications in java

I wants to learn making a desktop applications...Please suggest me any book or site where I can get reference
VIEWS ON THIS POST

56

Posted on:

Saturday 22nd September 2012
View Replies!

All About making your own web browser

Seeing Different videos on the net and reading basic books about Java I managed to create a basic web browser but the problem was that I couldn't translate the web pages as they are presented in google chrome for example and when I was pressing the google button in order to search for something it turned to do nothing except an annoying voice like beeep.How can I solve this problem.Thank you all in advance and most of you I thank this forum that have helped me many times in the past . Code is below: package javagui.views; import java.awt.AWTEvent; public class ReadFileMain extends JFrame { private JPanel contentPane; private JTextField addressBar; private JEditorPane display; private String HoldPreviousURL; private String HoldCurrentURL,CorrectURL; public String[] UrlStrings; public List list1 = new ArrayList(); public int i=0; //private MouseListener mouseListener; public static int k=0; public static int p=-1; public String Common = ""; public String Home = "http://google.com"; public JTextField jtf; private JPopupMenu Pmenu; public JMenuItem menuItem; private JButton Bck; private JButton Fwd; private JButton btnHome; private JTextField txtHome; public static JProgressBar progressBar = new JProgressBar(); private int value; private JButton btnStart; public static int Enab = 0; public static int i1 = 0; public static int i2 = 0; public static int i3 = 0; public static int i4 = 0; public static int i5 = 0; public static int i6 = 0; public static int i7 = 0; public static int life; /** * Launch the application. */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { ReadFileMain frame = new ReadFileMain(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public ReadFileMain() { setIconImage(Toolkit.getDefaultToolkit().getImage(ReadFileMain.class.getResource("/javagui/resources/img16x16/16x16-Gear.jpg"))); setBackground(new Color(0, 102, 0)); setTitle("PetroS Browser"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 765, 498); HandClass2 Handler2 = new HandClass2(); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnNew = new JMenu("New"); menuBar.add(mnNew); JMenuItem mntmNewTab = new JMenuItem("New Tab"); mnNew.add(mntmNewTab); JMenuItem mntmCloseInstance = new JMenuItem("Close Instance"); mntmCloseInstance.addActionListener(Handler2); mnNew.add(mntmCloseInstance); contentPane = new JPanel(); contentPane.setBackground(new Color(0, 0, 0)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); addressBar = new JTextField("enter a URL !"); addressBar.setColumns(10); addressBar.select(); addressBar.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ k=1; CorrectURL=event.getActionCommand(); p++; progressBar.setValue(0); if(CorrectURL.startsWith("http://")){ Common = loadCrap(CorrectURL); } else{ Common = loadCrap("http://" + event.getActionCommand()); } } } ); MouseEvent1 mouseListener1 = new MouseEvent1(); addressBar.addMouseListener(mouseListener1); MouseEvent2 mouseListener2 = new MouseEvent2(); /*display.invalidate(); jScrollPane.validate(); scrollBar.setValue(scrollBar.getMaximum() - scrollBar.getVisibleAmount());*/ //getContentPane().add(new JScrollPane(display)); //setSize(774,451); //setVisible(true); btnHome = new JButton(""); btnHome.setIcon(new ImageIcon(ReadFileMain.class.getResource("/javagui/resources/img16x16/16x16-home-icon.png"))); Bck = new JButton(""); Bck.setIcon(new ImageIcon(ReadFileMain.class.getResource("/javagui/resources/img16x16/16x16-Arrow-back.png"))); Fwd = new JButton(""); Fwd.setIcon(new ImageIcon(ReadFileMain.class.getResource("/javagui/resources/img16x16/16x16-Arrow forward.png"))); JScrollPane scrollPane = new JScrollPane(); txtHome = new JTextField(); txtHome.setBackground(new Color(51, 51, 51)); txtHome.setText("Home:"); txtHome.setColumns(10); txtHome.setVisible(false); //progressBar = new JProgressBar(0,100); progressBar.setStringPainted(true); progressBar.setBorderPainted(true); progressBar.setForeground(new Color(0, 128, 0)); //progressBar.setValue(0); btnStart = new JButton(""); btnStart.setIcon(new ImageIcon(ReadFileMain.class.getResource("/javagui/resources/img16x16/16x16-start4.jpg"))); //progressBar.updateUI(); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addContainerGap() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 703, Short.MAX_VALUE) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(Bck, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(Fwd, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE) .addGap(2) .addComponent(addressBar, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(btnStart) .addGap(8) .addComponent(btnHome)) .addComponent(txtHome, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 703, Short.MAX_VALUE)) .addGap(26)) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(progressBar, GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE) .addGap(28)))) ); gl_contentPane.setVerticalGroup( gl_contentPane.createParallelGroup(Alignment.TRAILING) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(txtHome, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false) .addComponent(Bck, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Fwd, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(btnHome) .addComponent(addressBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(btnStart)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(progressBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); display = new JEditorPane(); scrollPane.setViewportView(display); display.setContentType("text/html"); display.setEditable(false); display.addMouseListener(mouseListener2); display.addHyperlinkListener( new HyperlinkListener(){ public void hyperlinkUpdate(HyperlinkEvent event){ if(event.getEventType()==HyperlinkEvent.EventType.ACTIVATED){ k=1; p++; Common = loadCrap(event.getURL().toString()); } } } ); display.setEnabled(false); HandlerClass1 handler1 = new HandlerClass1(); HandlerClass2 handler2 = new HandlerClass2(); HandlerClass3 handler3 = new HandlerClass3(); HandlerClass4 handler4 = new HandlerClass4(); Bck.addActionListener(handler1); Fwd.addActionListener(handler2); btnHome.addActionListener(handler3); btnStart.addActionListener(handler4); contentPane.setLayout(gl_contentPane); } //load crap to display on the screen @SuppressWarnings("deprecation") private String loadCrap(String userText){ try{ String Com; int N=0; if(k==1){ list1.add(userText); } //progressBar.setValue(0); for(life = 0; life
VIEWS ON THIS POST

86

Posted on:

Saturday 22nd September 2012
View Replies!

making a JFrame nonFocusable

JOptionPane has methods which take a component as an argument, like this: JFrame frame = new JFrame(); JOptionPane.showConfirmDialog(frame, "Do you want to save this file");
VIEWS ON THIS POST

59

Posted on:

Monday 24th September 2012
View Replies!

interactive real 3d in GUI

Hi .I am quite new to java world I encountered a project need to have a real model interacting in a java gui(I believe inside a JPanel). I've been told to use vrml but it seems explorers can work with vrml player or cant integrate those with java. can somebody tell me how put this real 3d cad model in java gui with interaction or should I ask this in another forum\t
VIEWS ON THIS POST

36

Posted on:

Tuesday 25th September 2012
View Replies!

making the message wrap in a JDialog

i have the following code which works ok except the message doesn't wrap, so the JDialog(the lucky recipient of the return value from getMessage()), is one long...long...long..line import java.util.ArrayList; import java.math.BigInteger; class Euler8 implements Problem { String string = ("" + "73167176531330624919225119674426574742355349194934" + "96983520312774506326239578318016984801869478851843" + "85861560789112949495459501737958331952853208805511" + "12540698747158523863050715693290963295227443043557" + "66896648950445244523161731856403098711121722383113" + "62229893423380308135336276614282806444486645238749" + "30358907296290491560440772390713810515859307960866" + "70172427121883998797908792274921901699720888093776" + "65727333001053367881220235421809751254540594752243" + "52584907711670556013604839586446706324415722155397" + "53697817977846174064955149290862569321978468622482" + "83972241375657056057490261407972968652414535100474" + "82166370484403199890008895243450658541227588666881" + "16427171479924442928230863465674813919123162824586" + "17866458359124566529476545682848912883142607690042" + "24219022671055626321111109370544217506941658960408" + "07198403850962455444362981230987879927244284909188" + "84580156166097919133875499200524063689912560717606" + "05886116467109405077541002256983155200055935729725" + "71636269561882670428252483600823257530420752963450"); public String solve() { ArrayList list = new ArrayList(); int answer = 0; return string; } public String getMessage() { return "Find the greatest product of five consecutive digits in the 1000-digit number." + string; } }
VIEWS ON THIS POST

90

Posted on:

Wednesday 26th September 2012
View Replies!

need help with making a 4x4 grid. code and details inside.

I'm trying to make a 4x4 grid of boxes with each having a different color. i have some code written for the grid but am still pretty clueless on how to continue it and also how to import the colors. I told my professor(which is an online course) that I was never shown an example of a grid but his reply was very short. I'm working with Applets. just fyi here is the box code public class Box { private int upperLeftX; private int upperLeftY; private int height; private int width; private Color boxColor; public Box(int upperX, int upperY, int h, int w, Color myColor){ this.upperLeftX = upperX; this.upperLeftY = upperY; this.height = h; this.width = w; this.boxColor = myColor; } public int getUpperLeftX() { return upperLeftX; } public void setUpperLeftX(int upperLeftX) { this.upperLeftX = upperLeftX; } public int getUpperLeftY() { return upperLeftY; } public void setUpperLeftY(int upperLeftY) { this.upperLeftY = upperLeftY; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public Color getBoxColor() { return boxColor; } public void setBoxColor(Color boxColor) { this.boxColor = boxColor; } public void display(Graphics g){ g.fillRect(upperLeftX,upperLeftY,width,height); g.setColor(boxColor); } }
VIEWS ON THIS POST

112

Posted on:

Friday 28th September 2012
View Replies!

program making the whole screen to be blue instead of drawing

Can anyone help with a code please I need to draw a Mandelbrot set. import javax.swing.*; import java.awt.*; public class MPanel extends JPanel { // int count; JFrame frame; public MPanel(JFrame frame) { this.frame = frame; } public void init() { frame.add(this); this.setSize(700, 700); // frame.setSize(700,700); repaint(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint(Graphics g) { double factor = 1e6; double widthPixel; double heightPixel; for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { widthPixel = Math .round((x / this.getWidth() * factor) / factor); heightPixel = Math.round((y / this.getHeight() * factor) / factor); double re = (-2 + widthPixel * 4); double im = (1.6 - heightPixel * 3.2); Complex c = new Complex(re, im); // Complex temp = new Complex(x * widthPixel, y * heightPixel); Complex temp = c; for (int count = 0; count < 100; count++) { // Complex temp = c; c.square(); c.add(temp); System.out.println(c.toString()); // c.toString(); if (c.modulusSquared() > 4) { chooseColor(g, count); // System.out.println(count); g.drawLine(x, y, x, y); break; } } } } } public void chooseColor(Graphics g, int count) { if (count
VIEWS ON THIS POST

91

Posted on:

Friday 28th September 2012
View Replies!

making JTable appear after initial load

Hi Guys, I'm creating an app that includes a JTable. However, I don't want the JTable to appear upon the initial launch of the application. I have a File/New menu that I want the user to use to make the JTable appear for the first time with one new row in it. This is what I have for my actionPerformed(ActionEvent event) method: public void actionPerformed(ActionEvent event) { if(event.getSource() == mnuNew) { if(fileOpen) { if(isDirty) { ... } } else { if(isDirty == false) { System.out.println("setting up new table"); createTable(); addNewBlankRow(); table.validate(); //DOESN'T DO ANYTHING table.repaint(); //DOESN'T DO ANYTHING container.repaint(); //DOESN'T DO ANYTHING } } } ... }
VIEWS ON THIS POST

44

Posted on:

Monday 1st October 2012
View Replies!

Need help in making my Oval increase in size.

Hi ! I need a little help in creating shapes. Below is my code, but no matter what I do, I cannot make the Oval increase gradually (ie. once I run the program I should be able to see it increase). Any advice
VIEWS ON THIS POST

119

Posted on:

Tuesday 2nd October 2012
View Replies!

JTree making a node act as parent

I want to make a node to reflect as a Parent node containing children (Means i need the "+" sign associated with that node when shown in JTree). Currently I am using the TreeSelectionListener interface to do some operation when a node is selected in the JTree. But I would like to do some operation only when the node is expanded using the TreeExpansionListener interface. At this point there is only a Root and say some 10 children under the root. I want all the 10 children to behave like a collapsed node (pretend they have some children within them). Is there a way I can do this If not how to use the TreeExpansionListener for a leaf node(bit awkward)
VIEWS ON THIS POST

66

Posted on:

Wednesday 17th October 2012
View Replies!

Eclipse's AbstractTextEditor - making links "alive"

Hi I have a basic class i've written extending AbstractTextEditor. I use it only to display text files, not to edit them. I want that when the text contains links (or paths like /usr/bin/mydir) - they will be clickable and i can control what happens when user clicks on them. If they can be drawn in another color, it's even better. How can I do that
VIEWS ON THIS POST

80

Posted on:

Wednesday 17th October 2012
View Replies!

ribbon diagram

how to make ribbon diagram for java API\t
VIEWS ON THIS POST

13

Posted on:

Wednesday 17th October 2012
View Replies!

making buttons circular

hey , im wondering if theres an easy way to make jbutton circular instead of rectangular. Suppose if i have a: class Mybutton extends JButton{ } im guessing i would have to override paintComponent but im not too good on the swing side of things. If anyone has any suggestions let me know. Sincely, Chris Dancy
VIEWS ON THIS POST

58

Posted on:

Thursday 18th October 2012
View Replies!

GridBagLayout resizing is making component invisible

So I'm working on an app that has a JSplitPane. The right pane of the JSplitPane is a GridBagLayout ( I didn't choose it, the previous developers did). In it is a JTextField that is approx 10 characters wide. *Problem* If I make the GridBagLayout pane larger, everything works fine. But if I shrink it by setting the JSplitPane divider to halfway, the text field completely disappears, even though there is obviously more space to the right of it. I've set the JTextField's gridwidth to be the maximum possible, but it still disappears. Any suggestions\t
VIEWS ON THIS POST

112

Posted on:

Monday 22nd October 2012
View Replies!