みなさん、こんにちは。だから私の問題は、JtextAreaに挿入されたものを条件としてJPanelに何かを描画したいということです。これは正しいですか? : 挿入操作をチェックする DocumentListener :
protected class MyDocumentListener extends JPanel implements javax.swing.event.DocumentListener {
@Override
public void changedUpdate(javax.swing.event.DocumentEvent e) {
// text has been altered in the textarea
}
@Override
public void insertUpdate(javax.swing.event.DocumentEvent e)
{
// text has been added to the textarea
try {
//if not prompt Line
if (!Traffic.getText(Traffic.getLineStartOffset(Traffic.getLineCount()-1),
Traffic.getLineEndOffset(Traffic.getLineCount()-1)- Traffic.getLineStartOffset(Traffic.getLineCount()-1)).contains(">>"))
{//if a line after a replace has been inserted
if (Traffic.getLineCount() == (lastreplace + 2) )
{
System.err.println(Traffic.getText(Traffic.getLineStartOffset(lastreplace),
Traffic.getLineEndOffset(lastreplace) -
Traffic.getLineStartOffset(lastreplace)));
PortArchitecture (Traffic.getText(Traffic.getLineStartOffset(lastreplace),
Traffic.getLineEndOffset(lastreplace) -
Traffic.getLineStartOffset(lastreplace)));
lastreplace +=1;
}
else//last line when it's not detected by the previous condition it'll be consumed here
{
System.err.println(Traffic.getText(Traffic.getLineStartOffset(lastreplace),
Traffic.getLineEndOffset(lastreplace) -
Traffic.getLineStartOffset(lastreplace)));
PortArchitecture (Traffic.getText(Traffic.getLineStartOffset(lastreplace),
Traffic.getLineEndOffset(lastreplace) -
Traffic.getLineStartOffset(lastreplace)));
}
}
Traffic.setCaretPosition(Traffic.getDocument().getLength());
} catch (BadLocationException ex) {
Logger.getLogger(TrafficSerialPort.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void removeUpdate(javax.swing.event.DocumentEvent e) {
// text has been removed from the textarea
}
}
条件を確認して JPanel に描画する方法:
public void PortArchitecture (String line) throws BadLocationException
{
Graphics2D gfx = (Graphics2D)graphicPanel.getGraphics();
String [] valuesId = new String [2];
valuesId = line.split(":");
/**switch (valuesId[0])
{
case "Port Number" : draw();
}*/
if(valuesId[0].contains("Port number"))
{
gfx.drawString("(PN)", 30, 10);
gfx.drawString(valuesId[1],30, 140);
}
if(valuesId[0].contains("Port Extension"))
{
gfx.drawString("(EXT)", 100, 10);
gfx.drawString(valuesId[1], 100, 140);
// draw(g);
}
if(valuesId[0].contains("Forward Extension"))
{
gfx.drawLine(140,80,140,110);
// draw(g);
}
if(valuesId[0].contains("ON-HOOK"))
{
// draw(g);
}
if(valuesId[0].contains("OFF-HOOK"))
{
// draw(g);
}
if(valuesId[0].contains("Forward status"))
{
if(valuesId[1].contains("FORWARDED"))
{
// draw(g);
}
else
{
// draw(g);
}
}
if(valuesId[0].contains("Dialing"))
{
//get dialed number
//draw(g);
}
}
もう1つ:いくつかの図面の表示に関する結果がありますが、アプリケーションを最小化するとすべてのグラフィックが消えます.repaint()を呼び出す必要があることはわかっていますが、いつ、どのように行うかわかりません. 助けてください!