Witam,
jak w temacie, program wyswietla pola do wprowadzenia wartosci x i wartosci y, problem tkwi w tym ze z niewiadmocyh mi przyczyn gdy dodalem kod aby mozna bylo wprowadzic wartosci y to nie wyswietla dla nich pol tekstowych - wyswietla tylko dla x, kombinuje juz dluzszy czas i nic, nie wiem juz co mam zrobic :/
package dynamic.frame.content;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
@SuppressWarnings("serial")
public class MyDynamicFrame extends JFrame
{
private JTextField pola_x [] = null;
private JTextField pola_y [] = null;
private int ilosc_pol=0;
private JPanel Pola = new JPanel();
public MyDynamicFrame()
{
super("wprowadzanie x i y");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel gorny_panel = new JPanel(new FlowLayout());
JLabel ipktf = new JLabel();
ipktf.setText("ilosc pkt funkcji :");
ipktf.setFont(new Font("Arial", Font.BOLD, 12));
final JTextField i_pkt_f = new JTextField(12);
JButton generateBtn = new JButton("pokaz pola");
generateBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
ilosc_pol=Integer.parseInt(i_pkt_f.getText());
updatepola_x();
updatepola_y();
}
});
JButton showBtn = new JButton("wyswietl zawartosc pol");
showBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
printpola_xText();
printpola_yText();
}
});
gorny_panel.add(ipktf);
gorny_panel.add(i_pkt_f);
gorny_panel.add(generateBtn);
gorny_panel.add(showBtn);
setLayout(new BorderLayout());
add(gorny_panel, BorderLayout.CENTER);
add(gorny_panel, BorderLayout.NORTH);
add(Pola, BorderLayout.CENTER);
updatepola_x();
updatepola_y();
pack();
setVisible(true);
}
public void updatepola_x()
{
JTextField tmppola_x [] = new JTextField[ilosc_pol];
for(int i=0; i<ilosc_pol; i++)
{
if(pola_x == null || i >= pola_x.length)
{
tmppola_x[i] = new JTextField(10);
}
else
{
tmppola_x[i] = pola_x[i];
}
}
pola_x = tmppola_x;
Pola.removeAll();
Pola.setLayout(new GridLayout(ilosc_pol,1));
for(int i=0; i<ilosc_pol; i++)
{
Pola.add(pola_x[i]);
}
Pola.revalidate();
Pola.repaint();
pack();
repaint();
}
public void printpola_xText()
{
if(pola_x != null)
{
for(JTextField textField : pola_x)
{
System.out.println(textField.getText());
}
}
}
public void updatepola_y()
{
JTextField tmppola_y [] = new JTextField[ilosc_pol];
for(int j=0; j<ilosc_pol; j++)
{
if(pola_y == null || j >= pola_y.length)
{
tmppola_y[j] = new JTextField(10);
}
else
{
tmppola_y[j] = pola_y[j];
}
}
pola_y = tmppola_y;
Pola.removeAll();
Pola.setLayout(new GridLayout(ilosc_pol,1));
for(int j=0; j<ilosc_pol; j++)
{
Pola.add(pola_y[j]);
}
Pola.revalidate();
Pola.repaint();
pack();
repaint();
}
public void printpola_yText()
{
if(pola_y != null)
{
for(JTextField textField : pola_y)
{
System.out.println(textField.getText());
}
}
}
/**
* @param args
*/
public static void main(String[] args)
{
new MyDynamicFrame();
}
}