Runnable接口和Thread类未导入。(Runnable interface and Thread class not imported. Why?)
我正在从Oracle的Java教程中学习并发性,我在本地机器上尝试了以下两个例子 -
public class HelloRunnable implements Runnable { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new Thread(new HelloRunnable())).start(); } }
和
public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); } }
这些例子很有用。 现在,请原谅我,如果这个问题看起来很奇怪,因为我是Java编程的新手,但为什么不是
Runnable
接口,在第一个例子中,并且两个例子中的Thread
类都被导入了?提前致谢!
I was learning about concurrency from the Oracle's Java Tutorials and I tried the following two examples in my local machine-
public class HelloRunnable implements Runnable { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new Thread(new HelloRunnable())).start(); } }
and
public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); } }
The examples worked. Now, Pardon me if the question seems very kiddish, as I am a novice in Java's programming, but why wasn't the
Runnable
interface, in first example, andThread
class, in both examples, imported?Thanks in advance!
原文:https://stackoverflow.com/questions/38813879
最满意答案
我想出了一个解决方案。 我在我的数据末尾放了一个占位符。 在我的例子中,我的占位符是“X”。 在每行的末尾是一个占位符。 现在我可以使用一个定义为带有“X”的单元格的范围。 然后我可以使用该范围在其左侧插入一列。 这是我的代码,以防任何人查看此内容以供参考。 我想我的代码比实际需要的多。
Sub Button_Click() Dim wb As Workbook Dim newdata As Range Dim StartCell As Range Dim LastRow As Long Dim LastColumn As Long Dim n As Range Set wb = Workbooks("VBA TEST BOOK.xlsm") Set newdata = wb.Worksheets("Sheet2").Range("B2:B8") Set StartCell = Cells.Find("X") wb.Worksheets("Sheet1").UsedRange LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column Set n = wb.Worksheets("Sheet1").Range(StartCell, wb.Worksheets("Sheet1").Cells(LastRow, LastColumn)) n.Activate ActiveCell.EntireColumn.Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromRightOrAbove Dim PasteDestination As Range Set PasteDestination = Cells.Find("X").Offset(0, -1) newdata.Copy PasteDestination.PasteSpecial xlPasteValues End Sub
干杯
I Figured out a solution. I put a place holder at the end of my data. In my example my placeholder is "X". At the end of each row is a placeholder. Now I can use a range that is defined as cells with "X" in them. I can then use that range to insert a column to the immediate left of it. Here is my code in case anyone ever looks this up for reference. I think I have more code than is actually necessary.
Sub Button_Click() Dim wb As Workbook Dim newdata As Range Dim StartCell As Range Dim LastRow As Long Dim LastColumn As Long Dim n As Range Set wb = Workbooks("VBA TEST BOOK.xlsm") Set newdata = wb.Worksheets("Sheet2").Range("B2:B8") Set StartCell = Cells.Find("X") wb.Worksheets("Sheet1").UsedRange LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column Set n = wb.Worksheets("Sheet1").Range(StartCell, wb.Worksheets("Sheet1").Cells(LastRow, LastColumn)) n.Activate ActiveCell.EntireColumn.Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromRightOrAbove Dim PasteDestination As Range Set PasteDestination = Cells.Find("X").Offset(0, -1) newdata.Copy PasteDestination.PasteSpecial xlPasteValues End Sub
Cheers
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
Excel:需要宏 - 2列数据成为1列“彼此”(Excel: Macro needed - 2 columns of data to become 1 column “every other”)[2023-12-27]
如果不插入空行,您可以执行以下操作。 它还计算具有2列的工作表上的最后一行,以便在循环结束时不需要硬编码。 评论应该有助于您了解每一步的发生情况。 然后,您可以修改它以使用您的特定工作簿。 你可以通过很多方式解决这个问题。 我选择将旋转结果放在第二张纸上。 Sub PivotTwoColumnsIntoOne() Dim wb As Workbook Dim src As Worksheet Dim tgt As Worksheet Dim rng As Range ... -
Excel VBA - “复制/粘贴”仅粘贴所选范围的值(Excel VBA - “Copy/Paste” pastes only value of selected range)[2022-11-09]
我不知道你有什么样的数据,但这应该可以解决问题: Dim RS As String RS = "A1:G" & Workbooks(fileToClose).ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row 'MsgBox RS Workbooks(fileToClose).ActiveSheet.Range("A1").EntireRow.Delete Workbooks(fileKeepOpen).Sheets("DATA").Range("B2: ... -
使用excel宏对特定列的数据求和并将数据传输到sheet2(using excel macro to sum data of specific column and transfer data to sheet2)[2023-12-31]
这可以使用公式SUMIFS完成 =SUMIFS(Sheet1!H:H,Sheet1!A:A,">=0",Sheet1!A:A,"<300") 该公式计算列H的总和, A列中的值介于0和299之间( >=0 and <300 ) =SUMIFS(Sheet1!H:H,Sheet1!A:A,">=300",Sheet1!A:A,"<600") 该公式计算列H的总和, A列中的值介于300和599之间( >=300 and <600 ) 注意:确保使用正确的标准,例如300不包括在两个范围内(不重叠)。 第一 ... -
在我的最后一列之后创建一个粘贴数据列的按钮宏(Make a Button Macro That Pastes a Column of Data After my Last Column)[2023-07-10]
我想出了一个解决方案。 我在我的数据末尾放了一个占位符。 在我的例子中,我的占位符是“X”。 在每行的末尾是一个占位符。 现在我可以使用一个定义为带有“X”的单元格的范围。 然后我可以使用该范围在其左侧插入一列。 这是我的代码,以防任何人查看此内容以供参考。 我想我的代码比实际需要的多。 Sub Button_Click() Dim wb As Workbook Dim newdata As Range Dim StartCell As Range Dim LastRow As Long Dim Last ... -
Excel新列宏(Excel new column macro)[2022-09-12]
如果你打算输入一个公式你应该 使用Formula属性而不是Value属性 使用EN-US语言环境(对于函数名称等)编写公式 - 或者如果您愿意,可以使用FormulaLocal属性,但如果他们尝试使用您的代码,那么其他语言环境中的某个人将收到错误 确保通过使用""来转义公式中的任何"标记"" Sub AddData() lastRow = Sheets("Sheet2").Cells(65536, 2).End(xlUp).Row Sheets("Sheet2").Range("A2:A ... -
多列宏(Macro For MULTIPLE Columns)[2021-07-26]
在我的结尾处进行了简单的测试和运行,没有错误。 我很确定这会做你想要的。 如果没有,请告诉我,我会再次尝试: Sub MonthlyCost() Dim columnStart As Long Dim columnsToCopy As Long Dim columnEnd As Long Dim i As Long columnsToCopy = 5 columnStart = 86 ' this is column CH columnEnd = columnStart + columnsToCopy ... -
将宏应用于整个列(Applying a macro to an entire column)[2022-04-03]
将其放在要触发文件夹选择的工作表的代码模块中: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.CountLarge = 1 And Target.Cells(1).Column = 1 Then With Application.FileDialog(msoFileDialogFolderPicker) .InitialFileName = IIf(tar ... -
未经测试但编译好了: Sub CopyByHeader() Dim shtA As Worksheet, shtB As Worksheet Dim c As Range, f As Range Dim rngCopy As Range, rngCopyTo Set shtA = ActiveSheet ' "incoming data" - could be different workbook Set shtB = ThisWorkbook.Sheets("M ...