我从事股票市场项目。我想制作显示股票市场图表和新闻的桌面应用程序。到目前为止,我已经制作了一个主框架(类),它有RSS,第二个是applcationframe,显示蜡烛图表(2类)。我想把图表放到我的主框架中。如何将它放入我的主框架/(或者如何将应用程序框架调用到框架中)。我将真正感谢所有的建议。
这是主框架的代码:
import java.awt.BorderLayout;
public class Boeing extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Boeing frame = new Boeing();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static String readRSS(String urlAddress) {
try{
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String sourceCode = "";
String line;
while((line = in.readLine())!=null) {
if (line.contains("<title>")){
int firstPos = line.indexOf("<title>");
String temp = line.substring(firstPos);
temp = temp.replace("<title>", "");
int lastPos = temp.indexOf("</title>");
temp = temp.substring(0,lastPos);
sourceCode += temp + "\n" + "\n";
}
}
in.close();
return sourceCode;
} catch (MalformedURLException ue){
System.out.println("Malformed URL");
} catch (IOException ioe) {
System.out.println("Something went wrong reading the cotents");
}
return null;
}
public Boeing() {
setResizable(false);
setExtendedState(Frame.MAXIMIZED_BOTH);
setTitle("StockIn");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1350, 695);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 1280, 22);
contentPane.add(menuBar);
JMenu mnStockin = new JMenu("StockIn");
menuBar.add(mnStockin);
JMenuItem mntmQuitStockin = new JMenuItem("Quit StockIn");
mntmQuitStockin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JMenuItem mntmHome = new JMenuItem("Home");
mntmHome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Intro intro = new Intro();
intro.setVisible(true);
dispose();
}
});
mnStockin.add(mntmHome);
JSeparator separator = new JSeparator();
mnStockin.add(separator);
mnStockin.add(mntmQuitStockin);
JMenu mnLse = new JMenu("LSE");
menuBar.add(mnLse);
JMenuItem mntmBoeing = new JMenuItem("BOEING CO");
mntmBoeing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Boeing boeing = new Boeing();
boeing.setVisible(true);
dispose();
}
});
mnLse.add(mntmBoeing);
JSeparator separator_16 = new JSeparator();
mnTSE.add(separator_16);
mnTSE.add(mntmSony);
TextArea textArea = new TextArea(readRSS("http://boeing.mediaroom.com/news-releases-statements?pagetemplate=rss"));
textArea.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
}
});
textArea.setEditable(false);
textArea.setBounds(684, 396, 596, 277);
contentPane.add(textArea);
Panel panel = new Panel();
panel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent arg0) {
}
});
panel.setBackground(Color.PINK);
panel.setBounds(684, 28, 596, 368);
contentPane.add(panel);
/* JLabel dice1 = new JLabel();
ImageIcon one = new ImageIcon("/Users/odzayaBatsaikhan/Desktop/chart.png");
dice1.setLocation(20, 100);
dice1.setSize(1000, 400);
dice1.setIcon(one);
contentPane.add(dice1);*/
}
}
import java.awt.BorderLayout;
public class Boeing extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Boeing frame = new Boeing();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static String readRSS(String urlAddress) {
try{
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String sourceCode = "";
String line;
while((line = in.readLine())!=null) {
if (line.contains("<title>")){
int firstPos = line.indexOf("<title>");
String temp = line.substring(firstPos);
temp = temp.replace("<title>", "");
int lastPos = temp.indexOf("</title>");
temp = temp.substring(0,lastPos);
sourceCode += temp + "\n" + "\n";
}
}
in.close();
return sourceCode;
} catch (MalformedURLException ue){
System.out.println("Malformed URL");
} catch (IOException ioe) {
System.out.println("Something went wrong reading the cotents");
}
return null;
}
public Boeing() {
setResizable(false);
setExtendedState(Frame.MAXIMIZED_BOTH);
setTitle("StockIn");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1350, 695);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 1280, 22);
contentPane.add(menuBar);
JMenu mnStockin = new JMenu("StockIn");
menuBar.add(mnStockin);
JMenuItem mntmQuitStockin = new JMenuItem("Quit StockIn");
mntmQuitStockin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JMenuItem mntmHome = new JMenuItem("Home");
mntmHome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Intro intro = new Intro();
intro.setVisible(true);
dispose();
}
});
mnStockin.add(mntmHome);
JSeparator separator = new JSeparator();
mnStockin.add(separator);
mnStockin.add(mntmQuitStockin);
JMenu mnLse = new JMenu("LSE");
menuBar.add(mnLse);
JMenuItem mntmBoeing = new JMenuItem("BOEING CO");
mntmBoeing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Boeing boeing = new Boeing();
boeing.setVisible(true);
dispose();
}
});
mnLse.add(mntmBoeing);
JSeparator separator_16 = new JSeparator();
mnTSE.add(separator_16);
mnTSE.add(mntmSony);
TextArea textArea = new TextArea(readRSS("http://boeing.mediaroom.com/news-releases-statements?pagetemplate=rss"));
textArea.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
}
});
textArea.setEditable(false);
textArea.setBounds(684, 396, 596, 277);
contentPane.add(textArea);
Panel panel = new Panel();
panel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent arg0) {
}
});
panel.setBackground(Color.PINK);
panel.setBounds(684, 28, 596, 368);
contentPane.add(panel);
/* JLabel dice1 = new JLabel();
ImageIcon one = new ImageIcon("/Users/odzayaBatsaikhan/Desktop/chart.png");
dice1.setLocation(20, 100);
dice1.setSize(1000, 400);
dice1.setIcon(one);
contentPane.add(dice1);*/
}
}
这是单独的烛台图表:
如果我想创建一个在主框架中显示图表的方法,怎么办呢?
答案 0 :(得分:0)
IB TWS使用JFreeChart绘制图表。
您可以使用。
将HTML代码插入到摇摆中